Specifications

59ADOBE FLEX 3
Building and Deploying Adobe Flex 3 Applications
<?xml version="1.0"?>
<!-- optimize/ShowInitializationTime.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="callLater(showInitTime)">
<mx:Script><![CDATA[
import flash.utils.Timer;
[Bindable]
public var t:String;
private function showInitTime():void {
// Record the number of ms since the player was initialized.
t = "App startup: " + getTimer() + " ms";
}
]]></mx:Script>
<mx:Label id="l1" text="{t}"/>
</mx:Application>
This example uses the callLater() method to delay the recording of the startup time until after the application
finishes and the first screen updates. The reason that the
showInitTime function pointer is passed to the
callLater() method is to make sure that the application finishes initializing itself before calling the getTimer()
method.
For more information on using the
callLater() method, see “Using the callLater() method” on page 107.
Calculating elapsed time
Some operations take longer than others. Whether these operations are related to data loading, instantiation,
effects, or some other factor, it’s important for you to know how long each aspect of your application takes.
You can calculate elapsed time from application startup by using the getTimer() method. The following example
calculates the elapsed times for the
preinitialize and creationComplete events for all the form elements. You
can modify this example to show individual times for the initialization and creation of each form element.
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- optimize/ShowElapsedTime.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
initialize="init()">
<mx:Script><![CDATA[
[Bindable]
public var dp:Array = [
{food:"apple", type:"fruit", color:"red"},
{food:"potato", type:"vegetable", color:"brown"},
{food:"pear", type:"fruit", color:"green"},
{food:"orange", type:"fruit", color:"orange"},
{food:"spinach", type:"vegetable", color:"green"},
{food:"beet", type:"vegetable", color:"red"}
];