[转] UIComponent的生命周期(life cycle)

来源:互联网 发布:windows汇编和普通汇编 编辑:程序博客网 时间:2024/05/01 21:57

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

 

 

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

文件如下:

 

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

 

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

本站推荐过的<Programing Flex 2>那本书的最后一章

或者在自带的帮助中找Creating and Extending Flex 3 Components / Creating ActionScriptComponents / 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.

 

 

 

原创粉丝点击