Central ‘esque Methods for Flash’ & Flex’s ProgressBar

For those of you in Central withdrawl, like me, here is a conversion of the 2 methods that Central uses for it’s Shell to control the progress bar it has at the bottom. Flash and Flex have a ProgressBar component, where the label is underneath the progress animation itself. However, I really liked the elegance of the methods, so converted for a project I am using. They are merely a simple wrapper around Flash’/Flex’ ProgressBar component to act like Central’s built in one. You can still use the indeterminate and label getter/settters as well as the setProgress method, but this way just felt more encapsulated to me.

progress_pb.mode = "manual";

function setStatus(str:String):Void
{
        progress_pb.label = str;
}

function setProgress(val:Number):Void
{
        if(val < 0)
        {
                progress_pb.indeterminate = true;
        }
        else if(val == 0)
        {
                progress_pb.indeterminate = false;
                progress_pb.setProgress(0, 100);
        }
        else
        {
                progress_pb.indeterminate = false;
                progress_pb.setProgress(val, 100);
        }
}

I’ve been using it mainly for web service calls, like so:

// starting the call
setStatus("Calling remote method...");
setProgress(-1);

// in my result handler
setStatus("Method returned: " + result);
setProgress(0);

// in my fault handler
setStatus("Method failed to return: " + status);
setProgress(0);

// obviously, you can do the old-skool
// half-way done
setProgress(50);

One Reply to “Central ‘esque Methods for Flash’ & Flex’s ProgressBar”

  1. Along the same lines if you want to really integrate the progress bar to webservices call, you can do it by listening for the progress events of the response object.
    for example
    if ws is a Web Service Object then
    var call=ws.getSomeData();
    now the call.response is a XML object so you can check the progress using getBytesTotal and getBytesLoaded

    But there are two things to note.
    If the wsdl has not been loaded, you may not be able to get the status information.
    Second thing is that the webservice must set the content length http header

Comments are closed.