当前位置: 首页 > news >正文

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]


如果想详细的了解各个部分请看

本站推荐过的<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部分,直接看偶下边画的图吧

UIComponent liftCycle

keeping in mind what invalidation methods cause a call to what validation method

invalidateProperties( ) commitProperties( )
invalidateSize( ) measure( )
invalidateDisplayList( ) updateDisplayList( )

commitProperties()

This method’s purpose is to commit any values typically set by
using a setter function. Often the commitProperties( ) method is as simple as calling
super.commitProperties( ) and setting the cached values:

measure( )

The purpose of this method is to perform measurement calculation and define sizing
information for the framework.

As a general rule, you will typically use the children’s width and
height properties to retrieve the size values of children that do not inherit from
UIComponent. For children that do inherit from UIComponent, you will want to use the
getExplicitOrMeasuredWidth( ) and getExplicitOrMeasuredHeight( ) methods.

updateDisplayList( ) 设置位置和大小

In the measure( ) validation method we retrieved the size, and in the
updateDisplayList( ) method we will set the size and position the children. When
positioning and sizing children, if a child does not inherit from UIComponent you will
want to use the x and y properties for positioning and the width and height properties
for sizing. If a child does inherit from UIComponent, you should use the
setActualSize(width,height) method for sizing and the move(x,y) method for
positioning.

相关文章:

  • spring(一)IOC AOP
  • 深入分析Flex [Bindable] 以及使用方法
  • indy10 学习2
  • 一个网页设计需求方眼中的网页设计
  • 正则表达式入门以及记录
  • 谈谈网页设计师的成长之路
  • 07.常用的SQL语句
  • 初步接触html心得
  • AS3所有类的接口实现一览表
  • 分页查询中绑定变量
  • Oracle11g字符集AL32UTF8修改为ZHS16GBK详解
  • 我参加了“2010年度十大杰出IT博客”大赛,请朋友们支持!
  • 使用jQuery开发一个响应式超酷整合RSS信息阅读杂志
  • MeeGo handset 1.1开发环境[6]:封装*.src.rpm和*.rpm
  • 使用Windows Service Wrapper快速创建一个Windows Service
  • [译] React v16.8: 含有Hooks的版本
  • 0x05 Python数据分析,Anaconda八斩刀
  • 4月23日世界读书日 网络营销论坛推荐《正在爆发的营销革命》
  • canvas 绘制双线技巧
  • jdbc就是这么简单
  • Laravel 菜鸟晋级之路
  • Perseus-BERT——业内性能极致优化的BERT训练方案
  • 规范化安全开发 KOA 手脚架
  • 基于Android乐音识别(2)
  • 快速体验 Sentinel 集群限流功能,只需简单几步
  • 类orAPI - 收藏集 - 掘金
  • 前端存储 - localStorage
  • 前嗅ForeSpider中数据浏览界面介绍
  • 思维导图—你不知道的JavaScript中卷
  • 想使用 MongoDB ,你应该了解这8个方面!
  • 再谈express与koa的对比
  • NLPIR智能语义技术让大数据挖掘更简单
  • PostgreSQL 快速给指定表每个字段创建索引 - 1
  • 阿里云移动端播放器高级功能介绍
  • ​HTTP与HTTPS:网络通信的安全卫士
  • #gStore-weekly | gStore最新版本1.0之三角形计数函数的使用
  • #多叉树深度遍历_结合深度学习的视频编码方法--帧内预测
  • #我与Java虚拟机的故事#连载02:“小蓝”陪伴的日日夜夜
  • (Git) gitignore基础使用
  • (pojstep1.1.2)2654(直叙式模拟)
  • (八)c52学习之旅-中断实验
  • (第9篇)大数据的的超级应用——数据挖掘-推荐系统
  • (二) Windows 下 Sublime Text 3 安装离线插件 Anaconda
  • (附源码)ssm户外用品商城 毕业设计 112346
  • (附源码)小程序儿童艺术培训机构教育管理小程序 毕业设计 201740
  • (利用IDEA+Maven)定制属于自己的jar包
  • (十八)三元表达式和列表解析
  • (四)Linux Shell编程——输入输出重定向
  • (转)es进行聚合操作时提示Fielddata is disabled on text fields by default
  • (转)程序员疫苗:代码注入
  • **CI中自动类加载的用法总结
  • @value 静态变量_Python彻底搞懂:变量、对象、赋值、引用、拷贝
  • [20150707]外部表与rowid.txt
  • [AutoSar]BSW_Com02 PDU详解
  • [BUG] Authentication Error