views:

200

answers:

2

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 an event at the application level that corresponds to the preloader events: 1. Download complete 2. Initialization complete (same as Application creationComplete)

+1  A: 

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.
}
Sly_cardinal
This is a good example. The application can pull data from the preloader but you do not want to go the other way and try to push the data from the preloader to any part of the app (which would risk loading more of the app in the preloader inadvertently).
Sam
A: 

This worked!, thank you

Nishanthe