2010-03-02 99 views
0

1)preInitialize:該組件剛剛創建但沒有任何子組件存在時引發此事件。Flex自定義組件生命週期

2)initialize:在創建了組件及其所有子組件之後但在計算任何尺寸之前引發此事件。

3)creationComplete:在完成所有組件及其子項創建並執行所有佈局計算之後,甚至會調度此項。

4)applicationComplete:應用程序的所有組件已成功創建

我的問題在這裏

  1. 讓我們假設我創建一個按鈕組件,哪些子組件,然後後調度?任何人都可以在組件的子組件上深入解釋我。

  2. 任何人都可以給我看一個代碼示例,其中一個組件是創建的..我的意思是從頭開始自定義組件。

+0

通常我不會迴應,但有很好的機會,其他人會偶然發現這樣的帖子。 – 2010-03-02 17:07:09

回答

1

Flex SDK源代碼是你的朋友。在這裏查看:

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

(您也可以按CTRL-SHIFT-T在Flash Builder,然後輸入你想打開的框架組件的名稱訪問源代碼,任何框架類)。

  1. 看看mx.controls.ComboBase,它是mx.controls.ComboBox的超類。其createChildren()方法創建多個子項,包括邊框,箭頭按鈕和文本輸入。下拉列表(顯示ComboBox.dataProvider中的項目)在ComboBox中定義並動態創建/銷燬,因此不會在createChildren中創建。

  2. 所有這些類都是很好的例子,雖然有時實現可能更清晰。簡單的組件如Button,CheckBox和RadioButton是一個很好的開始。

+0

謝謝...非常清楚的解釋...如果可能的話,你可以給我一個例子,非常基本的一個我們擴展組件和創建我們自己的組件...我的意思是步驟和代碼... – Kevin 2010-03-02 19:22:45

2

我要解釋組件生命週期的3個階段:

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

    • 1.Birth:
 ==>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.Death
==>Removing Children: removeChild(), removeAllChildrens() 
    ==>Garbage Collection: Collecting memory 

成分LIF的廣泛概述ecycle如下...

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.