UIComponent的生命周期(life cycle)--转自N神的日志

我只转载我认为十分有意义的技术内容。N神的这篇当然值得,作为为数不多的RIA的初期技术BLOG希望他继续有这样的贡献,感激不尽

  写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]
  如果想详细的了解各个部分请看
  本站推荐过的<Programing Flex 2>那本书的最后一章
  或者在自带的帮助中找Creating and Extending Flex 3 Components / Creating ActionScript Components / Creating Advanced Visual Components in ActionScript
  偶简单总结了一下
  组件的life cycle包含3个阶段:initialization, update, destruction.
  initialization阶段又包括construction部分, attachment部分,和initialization部分,直接看偶下边画的图吧
  
  
  
  .....


本文转自
http://www.nshen.net/blog/article.asp?id=519  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值