开发者

javascript run function with adobe air

开发者 https://www.devze.com 2023-03-10 06:26 出处:网络
I am working on the adobe air with javascript and html. I want to run multiple functions in a function with show the percentange run on the each function but the percentage also show the last calculat

I am working on the adobe air with javascript and html. I want to run multiple functions in a function with show the percentange run on the each function but the percentage also show the last calculation please help me.

Edit: added code snippet from comment, but I may have butchered the layout.

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; } 

we want to calculation show the开发者_JAVA技巧 every after loaded functions. as percentage=25% to 100%


If you downloading several types of info and want to show summary progress, first you need to know bytes total of each download. When you get ProgressEvent from each operation, you may call function show():

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

Update: some clarifications
Load resource you need with Loader. Add event listener to ProgressEvent on Loader.contentLoaderInfo. There will be three listeners for three load operations - load admin data, client data and staff data. When you get progress event from each operation (track it with three vars), you will know download size total:

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 :)))

I'm assuming you will make single request for each of those three downloads.

0

精彩评论

暂无评论...
验证码 换一张
取 消