日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

Optimize a Flex application using deferred instantiations

發(fā)布時(shí)間:2024/4/15 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Optimize a Flex application using deferred instantiations 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

[轉(zhuǎn)載]http://cookbooks.adobe.com/post_Optimize_a_Flex_application_using_deferred_instant-15826.html

Problem

I have a flex application containing custom components. How can I add them to my Flex Application and make sure it's optimized ?

Solution

We'll use the "deferred instantiation" which mean creating and adding our component's children when we need to (typically when they have to be displayed).

Detailed explanation

My custom component

I have a custom component extending the Container Class. It's really simple as it only displays a picture :

WizardCat

package com.palleas.component
{
? import flash.display.DisplayObject;
??
? import mx.core.Container;
? import mx.core.UIComponent;
??
? public class WizardCat extends Container
? {
??? [Embed(source="http://www.cnblogs.com/../assets/wizardcat.png")]
??? protected var CatClass:Class;
????
??? public function WizardCat()
??? {
????? super();
????? trace("creating wizard cat !");
????? var cat:DisplayObject = new CatClass() as DisplayObject;
????? var catContainer:UIComponent = new UIComponent();
????? catContainer.addChild(cat);
????? addChild(catContainer);
??? }
? }
}

Doing this is really wrong and can be a serious performance issue. Furthermore, components extending the Container class (such as ViewStack, for example) sometimes defers the creation of their children due to the "creationPolicy" property not set to "ALL". This behavior is not here to annoy you but to optimize Flex application loading : instead of automatically draw a component, it will wait until the component is really needed, when it's displayed.

Deferred instantiation

To do the same thing properly, override the "createChildren()" method and create your children there. This way, even if the component is instanciated, it'll wait the application explicitly calls its createChildren() method to create its children (here, it's just a picture) :

package com.palleas.component
{
? import flash.display.DisplayObject;
??
? import mx.core.Container;
? import mx.core.UIComponent;
??
? public class WizardCat extends Container
? {
??? [Embed(source="http://www.cnblogs.com/../assets/wizardcat.png")]
??? protected var CatClass:Class;
????
??? public function WizardCat()
??? {
????? super();
??? }
????
??? override protected function createChildren():void
??? {
????? super.createChildren();
????? trace("creating wizard cat !");
????? var cat:DisplayObject = new CatClass() as DisplayObject;
????? var catContainer:UIComponent = new UIComponent();
????? catContainer.addChild(cat);
????? addChild(catContainer);
??? }
? }
}

As you can see in the picture below, it's still working !

Conclusion

The conclusion of this recipe if quite simple : avoid instanciating and adding children components in constructor. This way, your application should run a little bit smoother!

轉(zhuǎn)載于:https://www.cnblogs.com/Bill_Lee/archive/2011/05/17/2048292.html

總結(jié)

以上是生活随笔為你收集整理的Optimize a Flex application using deferred instantiations的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。