UIComponent之life cycle

 写flex组件,了解UIComponent的生命周期(life cycle)很重要,尤其是初始化(initialization)的过程很复杂,贴个文件可以很容易看清这个顺序

文件如下:

package
{
  import flash.events.Event;
  
  import mx.core.UIComponent;
  import mx.events.FlexEvent;
 
  public class UILifeCycle extends UIComponent
  {
    public function UILifeCycle()
    {
   super();
     trace("***[ constructor ]");
      
     //flash.events.Event
     this.addEventListener(Event.ADDED,onAdded);
     this.addEventListener(Event.ADDED_TO_STAGE,onAddedToStage);
     this.addEventListener(Event.REMOVED,onRemoved);
     this.addEventListener(Event.REMOVED_FROM_STAGE,onRemovedFromStage);
    
     //mx.events.FlexEvent;
     this.addEventListener(FlexEvent.ADD,onAdd);
     this.addEventListener(FlexEvent.REMOVE,onRemove);
     this.addEventListener(FlexEvent.PREINITIALIZE,onPreinitialize);
     this.addEventListener(FlexEvent.INITIALIZE,onInitialize);
     this.addEventListener(FlexEvent.CREATION_COMPLETE,onCreationComplete);
    
    }
    
    //flash.events.Event
    private function onAdded(eo:Event):void{trace(eo.toString())};
    private function onAddedToStage(eo:Event):void{trace(eo.toString())};
    private function onRemoved(eo:Event):void {trace(eo.toString())};
    private function onRemovedFromStage(eo:Event):void {trace(eo.toString())};
    
    //mx.events.FlexEvent;
    private function onAdd(eo:FlexEvent):void {trace(eo.toString())};
    private function onRemove(eo:FlexEvent):void{trace(eo.toString())};
    private function onPreinitialize(eo:FlexEvent):void{trace(eo.toString())};
    private function onInitialize(eo:FlexEvent):void{trace(eo.toString())};
 private function onCreationComplete(eo:FlexEvent):void{trace(eo.toString())};  
 
   override protected function createChildren():void{trace("***[ createChildren ]")}
   override protected function commitProperties():void{trace("***[ commitProperties ]")}
   override protected function measure():void{trace("***[ measure ]")}  
   override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{trace("***[ updateDisplayList]")}
  
  }
}


拖到舞台上发布就可以看到trace信息了

***[ constructor ]
[Event type="added" bubbles=true cancelable=false eventPhase=2]
[Event type="add" bubbles=false cancelable=false eventPhase=2]
[Event type="preinitialize" bubbles=false cancelable=false eventPhase=2]
***[ createChildren ]
[Event type="initialize" bubbles=false cancelable=false eventPhase=2]
***[ commitProperties ]
***[ measure ]
***[ updateDisplayList]
[Event type="creationComplete" bubbles=false cancelable=false eventPhase=2]
[Event type="addedToStage" bubbles=false cancelable=false eventPhase=2]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值