在Application的初始化过程中有4个函数,一直都对这个顺序比较模糊,最近改了一个代码才搞明白的顺序:
preinitialize
initialize
creationComplete
applicationComplete
测试的代码如下,里面还包括了点击按钮的事件顺序:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
backgroundGradientColors="[#67cbff, #fcffff]"
color="#000000"
fontSize="12"
preinitialize="report( event , 'preinitialize' )"
initialize="report( event , 'initialize' )"
creationComplete="report( event , 'creationComplete' )"
applicationComplete="report( event , 'applicationComplete' )"
>
<mx:Script>
<![CDATA[
[Bindable]
public var outTextData:String="";
public function report( event:Event , value:String ):void
{
outTextData += event.type + " " + String(flash.utils.getTimer()) + "\n";
}
]]>
</mx:Script>
<mx:TextArea
id="outTextArea"
text="{ outTextData }"
right="10" left="10" top="50" bottom="10" alpha="0.5"
wordWrap="false"
initialize="report( event , 'initialize' )"
creationComplete="report( event , 'creationComplete' )"
/>
<mx:Button
y="10" height="30" left="168" width="150"
id="HelloButton"
label="Say Hello"
initialize="report( event , 'initialize' )"
creationComplete="report( event , 'creationComplete' )"
rollOver="report( event , 'rollOver' )"
rollOut="report( event , 'rollOut' )"
click="report( event , 'click > Hello!' )"
/>
<mx:Button
id="GoodByeButton"
label="Say Goodbye"
y="10" left="10" height="30" width="150" color="#000000"
initialize="report( event , 'initialize' )"
creationComplete="report( event , 'creationComplete' )"
click="report( event , 'click > Goodbye!' )"
/>
<mx:Button
id="ClearButton"
label="Clear"
y="10" left="326" height="30" color="#000000" right="10"
initialize="report( event , 'initialize' )"
creationComplete="report( event , 'creationComplete' )"
click="outTextData='';report( event , 'click' )"
/>
</mx:Application>