flex优化技巧(一)

making your swf file assmall as possible

 

A development SWF file: You can create thistype of SWF file by choosing the File➪Export➪Release Build option. The SWF file doesn’t contain

extra information, such as debugging- oraccessibility-related code.

Instead, this type of SWF file is the mostappropriate one for production

deployment use.

 

A debug SWF file: The second type of SWFfile that you can produce is

a debug SWF file. The Flex compilergenerates this type of SWF filewhen

you debug a Flex application in FlexBuilder, either by clicking the Debug

icon in the main toolbar or by choosing Run➪Debug Application. A

debug SWF file contains extradebugging-specific information (such as

the line numbers of code file) and thus hasa larger size. Don’t deploy

a debug SWF file for production purposes.

 

File➪Export➪Release Build

or

 

modularizing flexapplications

 

You can modularize your Flex applicationsin two ways — by using either

Runtime Shared Libraries (RSLs) or Flexmodules

 

Taking Advantage ofPersistent Framework Caching

 

 

 

Diagnosing Memory Leaks

 

Two of the most common causes of memoryleaks are

The use ofDictionary objects

The creation ofevent listeners that don’t get garbage collected

 

An ActionScript Dictionary object allowsyou to create a map of objects,

called keys, in which a value can be storedin the Dictionary object and

looked up for retrieval based on the key’sidentity. It’s basically a grab bag in

which you can store objects or data forlater retrieval and use.

You can create an ActionScript Dictionaryobject so that if the only reference to the key object is the Dictionaryobject, the key object can be garbage collected. This functionality isdetermined by the weakKeys parameter

that’s passed in when you create a newDictionary object. By default, the

weakKeys parameter is false, meaning thekey object isn’t garbage collected, even if the only reference to it is theDictionary object. To avoid

memory leaks, and if you know that you canclean up objects whose only reference is the Dictionary object, toggle thatparameter to true when you

create a new Dictionary object asdemonstrated in the following line of

code:

public vardict:Dictionary = new Dictionary(true);

Whenever you create a

new event listener in ActionScript code by usingthe addEventListener

method call, you should set the last parameter totrue if you want the event

listener to be identified as a weak reference. Bydefault, this parameter

(useWeakReference) is false. To help prevent memoryleaks, toggle this

property to true as demonstrated in the followingline of code:

myButton.addEventListener(“click”,clickHandler, false, 0, true);

 

 

Performance OptimizationTips

www.adobe.com/devnet/flex/articles/client_perf.html

 

Make your startup code mean and lean

The most expensive call in the Flex framework isthe setStyle ActionScript

method. When your code, or the Flex framework code,calls the setStyle

method on any object, a tree of calls is producedso that the style that’s set

on a parent object is propagated down to allnecessary child objects.

Sometimes, this resulting tree can be quite large,so the call can take a long

time to execute. If you find yourself calling thesetStyle method frequently

in your application code, or you’re settingnumerous styles at startup of the

application or after a component has been created,look into other ways of

setting styles, such as using CSS style sheets orcreating <mx:Style/>

blocks in your application code.

 

Convert relative layout containersinto absolute positioning containers

 

Reevaluate your layout hierarchy

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值