繁体   English   中英

Flex自定义组件生命周期

[英]Flex Custom component Life cycle

1)preInitialize:当刚刚创建组件但不存在任何子组件时,引发此事件。

2)初始化:在创建组件及其所有子组件之后但在计算任何尺寸之前引发此事件。

3)creationComplete:在所有组件及其子组件都已创建并且所有布局计算完成之后,甚至调度此事件。

4)applicationComplete:在成功创建应用程序的所有组件后调度

我的问题在这里

  1. 假设我创建一个按钮组件,那么子组件是什么? 谁能深入解释我的组件的子组件。

  2. 谁能给我展示代码示例,其中创建了一个组件。.我的意思是从头开始创建一个自定义组件。

我将解释组件生命周期的三个阶段:

  1. 出生时间
  2. 生活
  3. 死亡

    • 1.出生
  ==>application instantiation ==>Create Properties, sizing ==>Add children 
  • 2.生活
  ==>Validate and Invalidate Properties and sizes ==>Update list commitProperties(), measure(), and updateDisplayList(). This is the way the functions communicate: invalidateProperties() –> commitProperties()‏ invalidateSize() –> measure()‏ invalidateDisplayList() –> updateDisplayList()‏ 
  • 3.死亡
  ==>Removing Children: removeChild(), removeAllChildrens() ==>Garbage Collection: Collecting memory 

组件生命周期的概述如下...

1. The constructor is called and initial properties are set.
2. The preinitialize event is dispatched.
3. The createChildren() function is called.
4. The initialize event is dispatched.
5. The commitProperties() function is called.
6. The measure() function is called (if necessary).
7. The layoutChrome() function is called (very rare and will not be covered in this post).
8. The updateDisplayList() function is called.
9. The creationComplete event is dispatched.
10. The updateComplete event is dispatched.

Flex SDK源代码是您的朋友。 在这里查看:

http://opensource.adobe.com/svn/opensource/flex/sdk/tags/3.5.0.12683/frameworks/projects/framework/src

(您还可以通过在Flash Builder中按CTRL-SHIFT-T,然后键入要打开的框架组件的名称来访问任何框架类的源代码)。

  1. 看一下mx.controls.ComboBase,它是mx.controls.ComboBox的超类。 它的createChildren()方法创建几个子项,包括边框,箭头按钮和文本输入。 下拉列表(显示ComboBox.dataProvider中的项目)在ComboBox中定义,并且是动态创建/销毁的,因此不会在createChildren中创建。

  2. 所有这些类都是很好的例子,尽管有时实现可能更简洁。 Button,CheckBox和RadioButton等简单组件是一个很好的起点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM