注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

神魔破杜梓的叨叨堂

Programming every day!

 
 
 

日志

 
 
 
 

Flex组件初始化生命周期  

2008-09-02 20:40:34|  分类: My Tech |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

原文来自Adobe live doc

The component instantiation life cycle describes the sequence of steps that occur when you create a component object from a component class. As part of that life cycle, Flex automatically calls component methods, dispatches events, and makes the component visible.

The following example creates a Button control in ActionScript and adds it to a container:

// Create a Box container.
var boxContainer:Box = new Box();
// Configure the Box container.

// Create a Button control.
var b:Button = new Button()
// Configure the button control.
b.label = "Submit";
...
// Add the Button control to the Box container.
boxContainer.addChild(b);

The following steps show what occurs when you execute the code to create the Button control, and add the control to the Box container:

  1. You call the component's constructor, as the following code shows:
    // Create a Button control. 
    var b:Button = new Button()
  2. You configure the component by setting its properties, as the following code shows:
    // Configure the button control.
    b.label = "Submit";

    Component setter methods might call the invalidateProperties(), invalidateSize(), or invalidateDisplayList() methods.

  3. You call the addChild() method to add the component to its parent, as the following code shows:
    // Add the Button control to the Box container.
    boxContainer.addChild(b);

    Flex performs the following actions:

    1. Sets the parent property for the component to reference its parent container.
    2. Computes the style settings for the component.
    3. Dispatches the preinitialize event on the component.
    4. Calls the component's createChildren() method.
    5. Calls the invalidateProperties(), invalidateSize(), and invalidateDisplayList() methods to trigger later calls to the commitProperties(), measure(), or updateDisplayList() methods during the next render event.

      The only exception to this rule is that Flex does not call the measure() method when the user sets the height and width of the component.

    6. Dispatches the initialize event on the component. At this time, all of the component's children are initialized, but the component was not sized or processed for layout. You can use this event to perform additional processing of the component before it is laid out.
    7. Dispatches the childAdd event on the parent container.
    8. Dispatches the initialize event on the parent container.
  4. During the next render event, Flex performs the following actions:
    1. Calls the component's commitProperties() method.
    2. Calls the component's measure() method.
    3. Calls the component's layoutChrome() method.
    4. Calls the component's updateDisplayList() method.
    5. Dispatches the updateComplete event on the component.
  5. Flex dispatches additional render events if the commitProperties(), measure(), or updateDisplayList() methods call the invalidateProperties(), invalidateSize(), or invalidateDisplayList() methods.
  6. After the last render event occurs, Flex performs the following actions:
    1. Makes the component visible by setting the visible property to true.
    2. Dispatches the creationComplete event on the component. The component is sized and processed for layout. This event is only dispatched once when the component is created.
    3. Dispatches the updateComplete event on the component. Flex dispatches additional updateComplete events whenever the layout, position, size, or other visual characteristic of the component changes and the component is updated for display.

Most of the work for configuring a component occurs when you add the component to a container by using the addChild() method. That is because until you add the component to a container, Flex cannot determine its size, set inheriting style properties, or draw it on the screen.

You can also define your application in MXML, as the following example shows:

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

<mx:Box>
<mx:Button label="Submit"/>
</mx:Box>
</mx:Application>

The sequence of steps that Flex executes when creating a component in MXML are equivalent to the steps described for ActionScript.

You can remove a component from a container by using the removeChild() method. If there are no references to the component, it is eventually deleted from memory by the garbage collection mechanism of Macromedia Flash Player 9 from Adobe.

  评论这张
 
阅读(695)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017