Mega Code Archive

 
Categories / Flex / Components
 

Show individual times for the initialization and creation of each form element

<!-- Code from Flex 4 Documentation "Using Adobe Flex 4". This user guide is licensed for use under the terms of the Creative Commons Attribution  Non-Commercial 3.0 License.  This License allows users to copy, distribute, and transmit the user guide for noncommercial  purposes only so long as    (1) proper attribution to Adobe is given as the owner of the user guide; and    (2) any reuse or distribution of the user guide contains a notice that use of the user guide is governed by these terms.  The best way to provide notice is to include the following link.  To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ -->     <!-- optimize/ShowElapsedTime.mxml --> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"     xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:s="library://ns.adobe.com/flex/spark"     initialize="init()" height="700">     <s:layout>         <s:VerticalLayout />     </s:layout>     <fx:Script>          [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"}              ];          public var sTime:Number;          public var eTime:Number;          public var pTime:Number;          private function init():void {              f1.addEventListener("preinitialize", logPreInitTime, true);              f1.addEventListener("creationComplete", logCreationCompTime, true);          }          private var isFirst:Boolean = true;          private function logPreInitTime(e:Event):void {              // Get the time when the preinitialize event is dispatched.              sTime = getTimer();              trace("Preinitialize time for " + e.target + ": " + sTime.toString());          }          private function logCreationCompTime(e:Event):void {              // Get the time when the creationComplete event is dispatched.              eTime = getTimer();              /* Use target rather than currentTarget because these events are              triggered by each child of the Form control during the capture              phase. */              trace("CreationComplete time for " + e.target + ": " + eTime.toString());          }        </fx:Script>     <mx:Form id="f1">         <mx:FormHeading label="Sample Form" id="fh1" />         <mx:FormItem label="List Control" id="fi1">             <mx:List dataProvider="{dp}" labelField="food" id="list1" />         </mx:FormItem>         <mx:FormItem label="DataGrid control" id="fi2">             <mx:DataGrid width="200" dataProvider="{dp}" id="dg1" />         </mx:FormItem>         <mx:FormItem label="Date controls" id="fi3">             <mx:DateChooser id="dc" />             <mx:DateField id="df" />         </mx:FormItem>     </mx:Form> </s:Application>