`
isiqi
  • 浏览: 16558923 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

Flex 组件实例化生命周期

阅读更多

当我们创建一个按钮、Group的时候,总想知道Flex在背后为我们做了哪些事情,尤其开发自定义组件的时候,对组件的实例化生命周期更是需要了解。Adobe 官方材料using_flex_4.pdf便详细介绍了组件实例化生命周期。

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 Group container:

// Create a Group container.

var groupContainer:Group = new Group();

// Configure the Group container.

groupContainer.x = 10; groupContainer.y = 10;

// Create a Button control.

var b:Button = new Button()

// Configure the button control.

b.label = "Submit"; ...

// Add the Button control to the Box container.

groupContainer.addElement(b);

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

1You call the components constructor, as the following code shows:

// Create a Button control.

var b:Button = new Button()

2You 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(), invalidateSkinState(), or invalidateDisplayList() methods.

3You call the addElement() method to add the component to its parent, as the following code shows:

// Add the Button control to the Box container.

gropContainer.addElement(b);

Flex then performs the following actions:

4Sets the parent property for the component to reference its parent container.

5Computes the style settings for the component.

6Dispatches the preinitialize event on the component.

7Calls the components createChildren() method. For skinnable components, this causes a call to attachSkin(), which calls partAdded(), for all static parts defined in the skin file.

8Calls the invalidateProperties(), invalidateSize(), invalidateSkinSate(), and invalidateDisplayList() methods to trigger calls to the commitProperties(), measure(), getCurrentSkinState(), 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.

9Dispatches the initialize event on the component. At this time, all of the components children are initialized, but the component has not been sized or processed for layout. You can use this event to perform additional processing of the component before it is laid out.

Because the initialize event is dispatched early in the component's startup sequence, make sure that none of your processing causes the component to invalidate itself. You typically perform any final processing during the creationComplete event.

10Dispatches the childAdd event on the parent container.

11Dispatches the initialize event on the parent container.

12During the next render event, Flex performs the following actions:

a Calls the components commitProperties() method. For skinnable components, the commitProperties() method calls the getCurrentSkinState() methods.

b Calls the components measure() method.

c Calls the components updateDisplayList() method.

13Flex dispatches additional render events if the commitProperties(), measure(), or updateDisplayList() methods call the invalidateProperties(), invalidateSize(), invalidateSkinSate(), or invalidateDisplayList() methods.

14After the last render event occurs, Flex performs the following actions:

a Makes the component visible by setting the visible property to true.

b 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.

c 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 addElement() 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:

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:s="library://ns.adobe.com/flex/spark">

<s:Group> <s:Button label="Submit"/> </s:Group>

</s: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 removeElement() method.

分享到:
评论

相关推荐

    flex 4 生命周期

    首先,组件的创建过程始于`initialize`事件,这是组件实例化后首次允许开发者进行属性设置的时刻。接着,`creationComplete`事件标志着组件的所有子组件都已创建并初始化完成,此时可以访问和操作组件树。 布局阶段...

    【完美翻译】Flex组件的生命周期

    Flex组件的生命周期是Adobe Flex应用程序开发中的核心概念,它涵盖了组件从创建到销毁的各个阶段。在Flex中,每个UI组件都有一个明确的生命周期,这个生命周期由一系列的事件和方法组成,开发者可以通过这些事件和...

    flex3组件和框架的生命周期

    在子类创建阶段,会实例化这个自定义子类,并进行进一步的初始化工作。 **子类显示阶段** 一旦所有必要的初始化工作完成,Flex框架就会显示应用程序的主界面。这意味着用户现在可以看到应用程序的UI,并开始与其...

    理解Flex3的组件和框架的生命周期.doc

    1. 构造阶段:组件实例化,初始化基本属性。 2. 添加阶段:组件被添加到容器中,可能触发容器的布局过程。 3. 初始化阶段:组件的初始化方法执行,如设置初始值和绑定事件监听器。 4. 失效机制阶段:组件在不活动时...

    理解Flex3的组件和框架的生命周期

    ### 理解Flex3的组件和框架的生命周期 #### Flex3组件与框架生命周期解析 Flex3是一款由Adobe推出的开源富互联网应用(RIA)开发框架,主要基于ActionScript 3.0语言。Flex3框架的强大之处在于其为开发者提供了...

    Flex组件生命周期[收集].pdf

    Flex组件生命周期是软件开发中关于Adobe Flex框架的重要概念,它涉及到UIComponent的创建、初始化、显示和销毁等各个阶段。Flex应用的根对象是SystemManager,这是一个Display Class,继承自flash.display.MovieClip...

    Flex3组件和框架的生命周期

    这是组件生命周期的开始阶段,主要完成组件实例化的过程。在这个阶段中,调用组件的构造函数进行初始化操作。此时,组件还没有被添加到显示列表中,也无法获取到任何父级容器的信息。 **组件的添加阶段** 一旦组件...

    Flex 自定义组件ImageViewer

    组件生命周期是每个Flex组件从创建到销毁所经历的一系列阶段。理解组件生命周期至关重要,因为它涉及到组件何时初始化、何时准备显示、何时接收用户输入以及何时被销毁。以下是一些关键的生命周期方法: 1. **...

    Flex入门实例教程

    二、Flex组件库 Flex提供了一个丰富的组件库,包括各种UI元素,如数据网格、图表、表单组件等。教程会教你如何利用这些组件快速构建用户界面,并通过样式和皮肤定制它们的外观。 三、Flex与数据交互 Flex能够轻松地...

    flex简单实例。flex比较简单的 组件特效,对初学者有很大帮助

    1. **组件生命周期**:每个Flex组件都有其特定的生命周期,包括初始化、测量、布局、绘制和更新阶段。了解这些阶段能帮助开发者更好地控制组件的行为。 2. **数据绑定**:Flex支持双向数据绑定,这意味着组件的属性...

    精讲Flex4组件开发(附源码)

    这个框架基于ActionScript编程语言和Flex组件库,允许开发者创建具有丰富图形、交互性和动态效果的Web应用程序。"精讲Flex4组件开发"的主题深入探讨了Flex4中的组件开发技术,特别是聚焦于Spark组件架构,这是Flex4...

    flex教程实例详解

    此外,还会介绍Flex中的事件处理、数据绑定和组件生命周期等核心概念。 “Flex部署”章节则关注如何将完成的Flex应用程序发布和部署到Web服务器,包括配置、打包和优化等环节。这部分内容对于开发者来说至关重要,...

    flex3_4 lifecycle

    1. **构造函数**:组件实例化时被调用,用于设置初始属性。 2. **createChildren()**:在此方法中,子组件被创建并添加到组件树中。 3. **measure()**:组件根据其内容和约束来计算理想的尺寸。 4. **layoutChildren...

    flex中的组件重写例子

    1. **实例化**:当需要组件时,Flex会创建组件实例。 2. **初始化**:组件会调用initialize()方法进行初始化,加载初始数据和设置默认值。 3. **布局**:组件调用测量(measure)和布置(layout)方法来确定其大小和...

    Flex的组件

    2. **组件生命周期**:每个Flex组件都有自己的生命周期,包括创建、初始化、显示、隐藏和销毁等阶段。理解这些阶段对于优化性能和处理组件状态至关重要。 3. **组件属性和事件**:每个组件都有一系列可配置的属性,...

    Flex4 Life cycle

    1. **Creation Complete**:组件实例被创建并初始化,所有属性和子组件都已设置完毕。这是开始处理依赖于组件完全创建的事件的合适时机。 2. **Preinitialize**:在组件的外观(皮肤)开始加载之前调用,用于进行...

    Flex3+组件拖放教程

    通过深入理解`DragManager`、`DragSource`的工作原理以及拖放事件的生命周期,开发者可以实现复杂且具有个性化的拖放交互。这个教程“Flex3+组件拖放教程--一路风尘.pdf”很可能会详细解释这些概念,并通过实例代码...

    Flex Application 初始化顺序

    Flex Application 初始化顺序是一个重要的概念,尤其对于开发Adobe Flex应用程序的开发者来说,理解这一流程能帮助他们更好地优化代码和管理应用程序的生命周期。Flex是基于ActionScript和MXML的框架,用于构建富...

Global site tag (gtag.js) - Google Analytics