开发者

Flex: Pass data from preloader to app?

开发者 https://www.devze.com 2022-12-16 16:12 出处:网络
I would like to track the customer experience in downloading and initializing my flex app. (a) Is there a way to pass data from preloader to the application? I would like to pass the time it takes to

I would like to track the customer experience in downloading and initializing my flex app. (a) Is there a way to pass data from preloader to the application? I would like to pass the time it takes to download and the time it takes to initialize. (b)Alternatively: Is there 开发者_JAVA技巧an event at the application level that corresponds to the preloader events: 1. Download complete 2. Initialization complete (same as Application creationComplete)


The "Showing the download progress of an application" article in the livedocs should help.

Based on that documentation, I would do something like this:

  • create a simple subclass of the DownloadProgressBar,
  • override the event listeners to track the amount of time that has elapsed during download/initialisation,
  • store the time values as static properties so you can access them from your Application once it's completed initialisation.

Here is an example of what I'm thinking (I've not compiled this code, it's more to give an idea of what I'm talking about).

package
{
public class TimedProgressBar extends mx.preloaders.DownloadProgressBar
{
    public static var startTime:Number = 0;
    public static var downloadCompleteTime:Number = 0;
    public static var RSLCompleteTime:Number = 0;

    public function TimedProgressBar() 
    {
        super();
        startTime = getTimer();
    }

    override protected function completeHandler(event:Event):void
    {
        super();
        downloadCompleteTime = getTimer();
    }

    override protected function rslCompleteHandler(event:RSLEvent):void
    {
        super();
        RSLCompleteTime = getTimer();
    }
}
}

Set that as your preloader in your Application.mxml and listen for the APPLICATION_COMPLETE event:

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
    preloader="TimedProgressBar"
    applicationComplete="applicationCompleteHandler(event)">


private function applicationCompleteHandler(event:FlexEvent):void
{
    var completeTime:Number = getTimer();

    var downloadTime:Number = TimedProgressBar.downloadCompleteTime - TimedProgressBar.startTime;
    var rslDownloadTime:Number = TimedProgressBar.RSLCompleteTime - TimedProgressBar.downloadCompleteTime;
    var totalInitTime:Number = completeTime - TimedProgressBar.startTime;

    // Do whatever logging you want with this information.
}
0

精彩评论

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

关注公众号