2011-06-05 32 views
1

我正在與Adobe和HTML的土坯空氣工作。我想在一個函數中運行多個函數,並顯示百分比運行在每個函數上,但百分比也顯示最後的計算,請幫助我。Adob​​e運行函數與土坯空氣

編輯:從評論中添加了代碼片段,但我可能會屠殺佈局。

function show_percentage() { 
down_admin() 
down_staff() 
down_client() } 
function down_admin() { 
down all information of admin from the server; flag=1; } 
function down_staff() { 
down all information of the staff falg=2; } 

我們想計算顯示每個加載後的函數。作爲百分比= 25%至100%

+1

你能告訴我們你有這個功能的代碼嗎? – DOK 2011-06-05 11:34:51

+0

功能顯示() – user781193 2011-06-05 11:41:52

+0

函數show_percentage() { down_admin() down_staff() down_client() } 功能down_admin() { 向下從服務器管理的所有信息; flag = 1; } function down_staff() { down down所有員工信息 falg = 2; } 我們想要計算每個加載後的函數顯示。 as percentage = 25%to 100% – user781193 2011-06-05 11:47:09

回答

0

如果您下載多種類型的信息並希望顯示摘要進度,首先您需要知道每個下載的總字節數。當你從每個操作得到ProgressEvent,你可以調用函數顯示():

function show() { 
    var progress = (adminBytesLoaded + staffBytesLoaded + clientBytesLoaded) * 100/
     (adminBytesTotal + staffBytesTotal + clientBytesTotal); 
    //show progress somehow 
} 

更新:一些澄清
加載你需要加載的資源。將事件偵聽器添加到Loader.contentLoaderInfo上的ProgressEvent。三個加載操作將會有三個監聽器 - 加載管理員數據,客戶端數據和員工數據。當你從每個操作獲得進展的事件(三瓦爾跟蹤它),你就會知道下載的總規模:

var adminTotal:int; 
var clientTotal:int; 
var staffTotal:int; 
var adminLoaded:int; 
var clientLoaded:int; 
var staffLoaded:int; 

function onAdminLoadProgress(event:ProgressEvent):void 
{ 
    adminLoaded = event.bytesLoaded; 
    adminTotal = event.bytesTotal; 
    //if other operations already going, show progress 
    if (clientTotal && staffTotal) 
    { 
     showProgress(); 
    } 
} 


function onClientLoadProgress(event:ProgressEvent):void 
{ 
    clientLoaded = event.bytesLoaded; 
    clientTotal = event.bytesTotal; 
    if (adminTotal && staffTotal) 
    { 
     showProgress(); 
    } 
} 

//write onStaffLoaded yourself as an exercise :))) 

我假設你會爲每一個這三個下載的單個請求。

+0

請告訴我如何將down函數轉換爲BytesLoaded的時間down – user781193 2011-06-10 09:54:37