五月综合缴情婷婷六月,色94色欧美sute亚洲线路二,日韩制服国产精品一区,色噜噜一区二区三区,香港三级午夜理伦三级三

您現(xiàn)在的位置: 365建站網(wǎng) > 365文章 > flex一些必備的基礎(chǔ)知識(shí)及其編譯的深度剖析

flex一些必備的基礎(chǔ)知識(shí)及其編譯的深度剖析

文章來(lái)源:365jz.com     點(diǎn)擊數(shù):750    更新時(shí)間:2009-11-15 17:05   參與評(píng)論

 下面是關(guān)于事件弱引用的:

如果我們使用強(qiáng)引用(默認(rèn)情況),F(xiàn)LASH的垃圾回收不會(huì)釋放這個(gè)引用實(shí)例,盡管你把這個(gè)對(duì)象置為null或是其它,除非你手動(dòng)去執(zhí)行removeListener()方法,這里還有一個(gè)方法就是在添加事件時(shí)候使用弱引用。 一般情況我們?cè)谔砑右粋€(gè)事件的時(shí)候,比如給一個(gè)按鈕添加一個(gè)onclick事件,我們的寫(xiě)法是: button.addEventListener(Event.click,onclick);這種時(shí)候是強(qiáng)引用,因?yàn)閍ddEventListener還有幾個(gè)默認(rèn)的參數(shù)useCapture=false,priority=0;useWeakReference=false , 因此添加一個(gè)弱引用的方法是: yourobject.addEventListener(Type, function, false, 0, true); 什么情況應(yīng)該使用強(qiáng)引用,什么情況不應(yīng)該使用呢? 當(dāng)一些變量是成員變量(比如界面上不需要?jiǎng)h除的BUTTON),這種它的生命周期和listener是一樣的(意思是中間不用動(dòng)態(tài)刪除在重復(fù)產(chǎn)生)這種情況我們不用考慮弱引用; 當(dāng)一些對(duì)象是不穩(wěn)定的,動(dòng)態(tài)變化的,比如TIMER,flashplayer認(rèn)為它是整個(gè)生命周期的,應(yīng)該使用弱引用,如果你使用強(qiáng)引用,這個(gè)timer對(duì)象將永遠(yuǎn)不會(huì)垃圾回收。(注意) 所以我們使用timer時(shí)候一定要這么寫(xiě):myTimer.addEventListener(TimerEvent.TIMER, onTimer, false, 0, true

類(lèi)級(jí)別成員函數(shù)不屬于垃圾回收的對(duì)象,因此可以對(duì)類(lèi)級(jí)別成員函數(shù)將 useWeakReference 設(shè)置為 true 而不會(huì)使它們受垃圾回收的影響。如果對(duì)作為嵌套內(nèi)部函數(shù)的偵聽(tīng)器將 useWeakReference 設(shè)置為 true,則該函數(shù)將作為垃圾回收并且不再是永久函數(shù)。如果創(chuàng)建對(duì)該內(nèi)部函數(shù)的引用(將該函數(shù)保存到另一個(gè)變量中),則該函數(shù)將不作為垃圾回收并仍將保持永久。

簡(jiǎn)單總結(jié):對(duì)一些不想永久保存的事件偵聽(tīng)函數(shù),使用弱引用,對(duì)一些固定的,永久保存的偵聽(tīng)器,如上面說(shuō)的類(lèi)級(jí)別的成員,請(qǐng)使用強(qiáng)引用。

下面是一些關(guān)于flex的生面周期的的基礎(chǔ)知識(shí):

  Initlization


Construction
Construction是組件構(gòu)造階段,組件的構(gòu)造器不能有必須的參數(shù)。在構(gòu)造函數(shù)中可以添加事件監(jiān)聽(tīng)器,初始化屬性。這個(gè)階段只做很少的事情。

Configuration
Configuration是組件的配置階段,組件的屬性,事件回調(diào)函數(shù),樣式和效果定義都在這個(gè)階段完成。你不應(yīng)該把這些任務(wù)推遲到Attachment和Initlization階段之后。

Attachment
Attachment階段是把該組件追加到顯示列表當(dāng)中,一個(gè)Flex組件會(huì)被一個(gè)Flex容器IContianer以addChild方法添加到顯示列表當(dāng)中。

Initlization
在Initlization初始化階段,組件會(huì)執(zhí)行一次完整的invalidation/validation周期。這個(gè)階段做的工作流程是:

  • 發(fā)出preinitialize事件。
  • 執(zhí)行方法createChildren()
  • 發(fā)出initialize事件。
  • 行一次完整的invalidation/validation周期。
  • 發(fā)出creationComplete事件。





2. Updating


用戶(hù)可能會(huì)與組件產(chǎn)生交互,組件的位置大小可能改變,樣式可能被重新賦值,也可能獲得焦點(diǎn)或者被禁用等等。這些情況的發(fā)生都用影響到組件外觀的變化。所以組件需要重繪自身來(lái)響應(yīng)這些變化。

Invalidation
如果一個(gè)組件的屬性改變,它可能就會(huì)標(biāo)記組件為失效狀態(tài)。

Validation
一個(gè)組件被標(biāo)記失效后,會(huì)驗(yàn)證是否需要更新組件,如果需要會(huì)調(diào)用相關(guān)的方法來(lái)更新。組件有三個(gè)極其重要的方法來(lái)更新自己:

  • commitProperties()
  • measure()
  • updateDisplayList(unscaledWidth,unscaledHeight)

除了這三個(gè)方法,還有一個(gè)重要的方法是styleChanged(styleName),當(dāng)某個(gè)樣式改變時(shí),styleChanged被調(diào)用,然后執(zhí)行Invalidation標(biāo)記組件。如果你有自定義一個(gè)組件,有一些法則必要得遵守:

不要在子類(lèi)中顯式調(diào)用commitProperties,measure和updateDisplayList這三個(gè)方法,你要做的是override,而不是call。如果你添加了新的樣式,同樣是要繼承styleChanged方法,加入自己的邏輯。



3. Destruction


Detachment
當(dāng)不需要這個(gè)組件時(shí),把它從顯示列表中移出。把組件從一個(gè)容器中移出再添加到另一個(gè)容器中比創(chuàng)建新的組件有更小的開(kāi)銷(xiāo)。

Garbage Collection

如果組件不再被引用時(shí),它就成為符合垃圾回收的對(duì)象了,所以垃圾回收的第一條準(zhǔn)則是不再有活動(dòng)的引用。
更加值得注意的是第二條準(zhǔn)則,即不包含使用了強(qiáng)引用的事件監(jiān)聽(tīng)器,Dictionary和Timer。
所以盡量使用弱引用是多么重要,但是同樣,小心你的弱引用在不該回收的時(shí)刻被回收了。例如對(duì)函數(shù)中的臨時(shí)變量使用弱引用,你可能得不到你想要的異步結(jié)果

上面值得我們注意的是:Update的細(xì)述: 

  • commitProperties()
  • measure()
  • updateDisplayList(unscaledWidth,unscaledHeight)
  • 是flash player在組件更新時(shí)自動(dòng)調(diào)用的 這也就是為什么不需要調(diào)用,而只需override .
  • 下面是是來(lái)自  整個(gè)flex程序運(yùn)行的基本過(guò)程:

    1. First, enough bytes for frame 1 are streamed down to the Flash Player.
    2. The Flash Player executes those bytes by creating a SystemManager instance.
    3. SystemManager instruct the Flash Player to stop at the end of frame 1.
    4. SystemManager then goes on to create the Preloader which creates the DownloadProgressBar control and pops that up on the client screen.
    1. The Preloader then starts tracking the rest of the bytes streaming in from the Flex SWF (or from external SWFs).
      Once all the bytes for the Flex framework and application code are in, the System Manager goes on to frame 2 and instantiates the Application instance.
    2. All RSLs and their associated classes are now loaded [into the ApplicationDomain]; note that the load order is in the order defined during app compile time.[3]
    • All class definitions used by the application (views, logic, etc) must be loaded prior to Frame 2. It is here, in Frame1, that your preloader code can even install patches to the Flex framework BEFORE the framework classes themselves are loaded.
    • This technique is called "monkey-patching" and will be used later
      when we are discussing the decryption process.
    1. Once the Application instance has been created, the SystemManager sets Application.systemManager to itself. This is how you, the application developer, can access the SystemManager at a later time.
    2. The Application dispatches the preinitialize event at the beginning of the initialization process.
    3. Application goes on to create its children. The method createChildren() is called on the application. At this point each of the application’s components is being constructed, and each component’s createChildren() will be also called. For detail, look at component lifecycle section.
    4. The Application dispatches the initialize event, which indicates that all application’s components have been initialized. However, at this state, all the components are not yet laid out.
    5. Eventually, once all the Application child controls and containers have been created, sized and positioned, the Application dispatches the creationComplete event.
    6. Once the creationComplete event has been dispatched, the Preloader removes the DownloadProgressBar control and the SystemManager adds the Application instance to the Flash Player display list. (The Flash Player display list is basically the tree of visible or potentially visible objects that make up your application. When you add and remove child components to your application, your basically just adding and removing them from the display list).
    7. Once the Application is added to the Flash Player display list, the Application dispatches its applicationComplete event
    8. The Application has been created and is up on the screen ready to be interacted with.

    對(duì)于后面幾條大家都比較熟悉,主要是前面幾條:下面對(duì)前面幾條做一下概述:

      flash player 加載足夠多的字節(jié)流后就通過(guò)SystemManager類(lèi)的實(shí)例來(lái)執(zhí)行這些字節(jié)流,并且讓flash player 停止在第一幀。然后創(chuàng)建Preloader  ,通過(guò)Preloader  創(chuàng)建 DownloadProgressBar并讓DownloadProgressBar顯示在屏幕上。

    Preloader然后跟蹤剩下的flex SWF的字節(jié)流 (包括外部的swf 比如 我們創(chuàng)建flex工程時(shí)都有的playerProductInstall.swf文件) 

    當(dāng)這些字節(jié)流都進(jìn)入flash player后,就進(jìn)入到第二幀Application的實(shí)例化過(guò)程

    如對(duì)本文有疑問(wèn),請(qǐng)?zhí)峤坏浇涣髡搲瑥V大熱心網(wǎng)友會(huì)為你解答??! 點(diǎn)擊進(jìn)入論壇

    發(fā)表評(píng)論 (750人查看,0條評(píng)論)
    請(qǐng)自覺(jué)遵守互聯(lián)網(wǎng)相關(guān)的政策法規(guī),嚴(yán)禁發(fā)布色情、暴力、反動(dòng)的言論。
    昵稱(chēng):
    最新評(píng)論
    ------分隔線(xiàn)----------------------------

    其它欄目

    · 建站教程
    · 365學(xué)習(xí)

    業(yè)務(wù)咨詢(xún)

    · 技術(shù)支持
    · 服務(wù)時(shí)間:9:00-18:00
    365建站網(wǎng)二維碼

    Powered by 365建站網(wǎng) RSS地圖 HTML地圖

    copyright © 2013-2024 版權(quán)所有 鄂ICP備17013400號(hào)