flex Optimization (2)

2010-07-25  来源:本站原创  分类:Flash  人气:192 

A few days ago to be a boss recommended articles, from 7yue brother's blog, the author is Sean Moore,

Original Address: http://www.insideria.com/2009/04/51-actionscript-30-and-flex-op.html

Finished with the program may not run after the bloated than usual attention to these key points to keep reminding themselves. Translated for later inspection from time to time.

1 Create a new array to avoid using its constructor.

To do so: var a = [];

Not do this: var a = new Array ();

2 Create the array is a great consumption of the operation, so please be careful for the following types of operations:

var vanityCollection01: Array = new Array ();

var vanityCollection02: Array = new Array ();

var vanityCollection03: Array = new Array ();

var vanityCollection04: Array = new Array ();

3, the fastest way to copy an array is:

var copy: Array = sourceArray.concat ();

4 No matter what way you are, set the value for the array element is a slow operation.

employees.push (employee);

employees [2] = employee;

5 in the array to get a value of speed is set to a value twice.

var employee: Employee = employees [2];

6, the attribute function is set to a static function, so use it when you do not need to instantiate a class object.

StringUtils.trim ("text with space at end");

Class definition:

package

(

public final class StringUtils

(

public static function trim (s: String): String

(

var trimmed: String;

/ / Logic implementation code

return trimmed;

)

)

)

7 using the const keyword to define constants in the run cycle that will happen to change the property value.

public const APPLICATION_PUBLISHER: String = "Company, Inc.";

8 When a class subclasses are no longer needed when it is defined as the final class.

public final class StringUtils

9 Giant long function names and variable names in Action Script 3 does not cause any additional consumption (in other languages as well)

someCrazyLongMethodNameDoesntReallyImpactPerformanceTooMuch ();

10 define multiple variables within a single line will not bring any performance improvements (in other languages as well)

var i = 0; j = 10; k = 200;

11 use of if and use logic to judge the switch so there is no difference between the memory consumption, such as:

if (condition)

(

/ / Processing logic under

)

With the use of switch

switch (condition)

(

case "A":

/ / A processing logic under

break;

case "B":

/ / B under the conditions of processing logic

break;

)

No memory consumption on the difference.

Determine if the logic used to do 12 hours, as much as possible in accordance with the most likely to happen in the order to order. For example:

if (most likely the case)

(

/ / Handle most likely to happen.

)

else if (sometimes happens)

(

/ / Handle sometimes happens.

)

else

(

/ / Handle no more than to judge the situation occurs.

)

13 AVM calculations within the loop body, it will be promoted to floating-point integer type int Number of data processing, (from fp9 to fp10, the virtual machine has changed, int, uint, number no longer before the conversion between so slow.)

14 Note that solution type conversion, Unknown type (unknown), illegal type (incorrect) issues.

15 careful use of uint, it would process slower.

var footerHex: uint = 0x00ccff;

16 in the iterator to use integers as the growth in volume

Should be used this way:

for (var i: int = 0; i <n; i + +)

Instead of:

for (var i: Number = 0; i <n; i + +)

17 Do not int variable assigned a small value.

This should be used:

var decimal: Number = 14.654;

Should not be:

var decimal: int = 14.654;

Division multiplication vs 18: 0.001 to replace the use of 5000 * 5000/1000.

19 If you want to or while in the body of the loop for the frequent use of a value, use a local variable to store it, rather than calculating it frequently.

This calculation is its frequent:

for (..){ a * 180 / Math.PI;)

Defined as a variable to store it:

var toRadians: Number = a * 180/Math.PI;

20 to avoid judging the conditions in the loop body to calculate, for example:

var len: int = myArray.lengh;

for (var i = 0; i <len; i ++){}

Not do this:

for (var i = 0; i <myArray.lengh; i + +) () (by! I have been so dry!)

21 use regular expressions to check for the string and use string functions to carry out a string search.

For example: zip code using regular expressions to do test

private var regEx: RegExp = / ^ [AZ] [0-9] [AZ] [0-9] [AZ] [0-9] $ / i;

private function validatePostal (event: Event): void

(

if (regEx.test (zipTextInput.text))

(

/ / Handle input formats to meet the situation

)

)

String query processing using string functions:

var string: String = "Search me";

var searchIndex: int = string.indexOf ("me");

var search: String = string.substring (searchIndex, searchIndex + 2);

22 try to re-use those of the "high consumption areas of memory," the object, for example, DisplayObjects, URLLoader.

23 Flex object reference design patterns:

createChildren ();

commitProperties ();

updateDisplayList ();

24 used Datagrids components as your last show means (if you believe you really have no way to use a regular list of features you want to achieve before using it)

25 avoid the use of iterators with scrolling function iteration data.

26 Avoid using setStyle () function (which in the Flex framework is the performance of the behavior of one of the largest consumption)

Excessive use of nested containers 27 is bound to reduce your program's performance. For example, the following nested this nausea.

<mx:Panel>

<mx:VBox>

<mx:HBox>

<mx:Label text="Label 1" />

<mx:VBox>

<mx:Label text="Label 2" />

</ Mx: VBox>

<mx:HBox>

<mx:Label text="Label 3" />

<mx:VBox>

<mx:Label text="Label 4" />

</ Mx: VBox>

</ Mx: HBox>

</ Mx: HBox>

</ Mx: VBox>

</ Mx: Panel>

28 You do not have to add the namespace of each container is the label, only the top-level container to do so. The following is unnecessary.

<Mx: Image xmlns: mx = " http://www.adobe.com/2006/mxml "

source = "avatar.jpg" width = "200" height = "200" />

29 to remove unnecessary containers to reduce container nesting.

30 to avoid the tag nested VBox container (eliminate redundancy)

<mx:Panel>

<mx:Label text="Label 1" />

<mx:Label text="Label 2" />

</ Mx: Panel>

<mx:Panel>

<mx:VBox>

<mx:Label text="Label 1" />

<mx:Label text="Label 2" />

</ Mx: VBox>

</ Mx: Panel>

31 in the mx: Application tag inside avoid using VBox tag. (Eliminate redundancy)

<? Xml version = "1.0" encoding = "utf-8"?>

<mx:Application xmlns:mx=http://www.adobe.com/2006/mxml>

<mx:Label text="Label 1" />

<mx:Label text="Label 2" />

</ Mx: Application>

Instead of:

<? Xml version = "1.0" encoding = "utf-8"?>

<mx:Application xmlns:mx=http://www.adobe.com/2006/mxml>

<mx:VBox>

<mx:Label text="Label 1" />

<mx:Label text="Label 2" />

</ Mx: VBox>

</ Mx: Application>

32 set to true Repeater's recycleChildren property can improve its performance (using the object had created before, rather than creating a new object)

<mx:Script>

<! [CDATA [

[Bindable]

public var repeaterData: Array = ["data 1", "data 2"];

]]>

</ Mx: Script>

<mx:Repeater dataProvider="{repeaterData}" recycleChildren="true">

<mx:Label text="data item: {repeater.currentItem}"/>

</ Mx: Repeater>

33 the frame rate (framerate) is set to 60 or less.

<? Xml version = "1.0" encoding = "utf-8"?>

<Mx: Application xmlns: mx = http://www.adobe.com/2006/mxml

frameRate = "45">

</ Mx: Application>

34 in each frame to avoid dealing with multiple display objects.

Replace the Timer event 35 events using ENTER_FRAME

Use:

public function onEnterFrame (event: Event): void

(

)

private function init (): void

(

addEventListener (Event.ENTER_FRAME, onEnterFrame);

)

Instead of using:

public function onTimerTick (event: Event): void

(

)

private function init (): void

(

var timer: Timer = new Timer ();

timer.start ();

timer.addEventListener (TimerEvent.TIMER, onTimerTick);

)

36 used in the multi-frame display objects, use the following method to postpone its object to create:

<mx:Container creationPolicy="queued"/>

37 alpha = 0 is not the same as visible = false (when the object is not visible will not be processing)

Therefore, use:

loginButton.visible = false;

Instead of:

loginButton.alpha = 0;

This article comes from CSDN blog, reproduced, please indicate the source: http://blog.csdn.net/TemateRoom/archive/2010/01/19/5206065.aspx

相关文章
  • flex Optimization (1) 2010-07-25

    As more and more Flex is well known, more and more Internet applications have begun RIA. As we all know, the current domestic broadband applications is not as well developed in many developed countries, individual applications are basically 2M below

  • flex Optimization (2) 2010-07-25

    A few days ago to be a boss recommended articles, from 7yue brother's blog, the author is Sean Moore, Original Address: http://www.insideria.com/2009/04/51-actionscript-30-and-flex-op.html Finished with the program may not run after the bloated than

  • The Complete Works of flex Optimization 2010-08-28

    1, when the time to create an array with a new operator to avoid using var a: Array = []; instead of var a: Array = new Array (); 2, the traditional way to resume the array, then the price is very expensive: var vanityCollection01: Array = new Array

  • Best written program ActionScript 3.0 (b) 2010-02-25

    Quoted and translated article written by Sean Moore Round up of ActionScript 3.0 and Flex optimization techniques and practices , lists of 51 Sean had the best of AS3 way, the response was compiled based on 37 readers a little skill. Although there a

  • Flex SEO (Search engine optimization), allow your browser to find your flash 2009-11-01

    Flex SEO (Search engine optimization), allow your browser to find your flash site Reprinted from http://qdhbroadway.spaces.live.com/blog/cns!1A95707CECDECA1B!417.entry The blog Search engine optimistation is to make your site information to be "searc

  • FLEX collection of memory optimization techniques 2010-03-30

    FLEX memory optimization principles released 1. Is deleted all references to objects in the external must be removed as a clean garbage collection system can be disposed of; 2. Parent child objects within other objects by an external reference, and w

  • Seek answers to Flex desktop CPU utilization optimization problems 2010-04-14

    I develop desktop applications using Flex a project, when a long running time, when, cpu usage is high, generally to 50 per cent, causing the program finishes off. . . The problem is I have long puzzled Procedure is used setInterval 1 minute refresh

  • [Change] Flex performance optimization techniques commonly used summary 2010-04-28

    As more and more Flex is well known, more and more Internet applications have begun RIA. As we all know, the current domestic broadband applications is not as well developed in many developed countries, individual applications are basically 2M below

  • The release of Flex Memory Optimization principle 2010-05-25

    Memory release optimization principles: 1. Is deleted all references to objects in the external must be removed as a clean garbage collection system can be disposed of; 2. Parent child objects within other objects by an external reference, and will l

  • Optimization of the overall framework of Flex 2010-05-25

    Optimization strategy: 1, the system has only one main application Application, others have adopted a Module module, on-demand loading Specifically, with reference to my previous blog post: http://zhangyinyou.javaeye.com/admin/blogs/669586 2 and ExtJ

  • flex memory release optimization 2010-06-21

    FLEX memory release optimization principles: 1. Is deleted all references to objects in the external must be removed as a clean garbage collection system can be disposed of; 2. Parent child objects within other objects by an external reference, and w

  • Flex performance optimization techniques commonly used summary 2010-07-30

    As more and more Flex is well known, more and more Internet applications have begun RIA. As we all know, the current domestic broadband applications is not as well developed in many developed countries, individual applications are basically 2M below

  • Flex performance optimization methods commonly used summary 2010-08-03

    1 u4 B4 O3 W "V! Q) y B &` 6 R; S As more and more Flex is well known, more and more Internet applications have begun RIA. As we all know, the current domestic broadband applications is not as well developed in many developed countries, individua

  • FLEX performance optimization article is reproduced 2010-08-20

    1. As more and more Flex is well known, more and more Internet applications have begun RIA. As we all know, the current domestic broadband applications is not as well developed in many developed countries, individual applications are basically 2M bel

  • Flex Development Module Optimization 2010-08-21

    Flex Module Optimization Article Category: Flash Programming Module is basically divided into two types: 1. Complete Module, can be used by external app - all related to the reference will be compiled into the module, the master file sizes are reduce

  • Flex garbage collection and performance optimization of a number of summary 2010-08-28

    Some knowledge of Flex garbage collection summary: 1, deleted all references to objects in the external must be removed as a clean garbage collection system can be disposed of. 2, the child within the parent object is an external reference other obje

  • FLEX memory optimization techniques set (reproduced) 2010-09-02

    1. Is deleted all references to objects in the external must be removed as a clean garbage collection system can be disposed of; 2. Parent child objects within other objects by an external reference, and will lead to the child object is not deleted,

  • Flex performance optimization project 2010-12-07

    Some knowledge of garbage collection summary: 1, deleted all references to objects in the external must be removed as a clean garbage collection system in order to be disposed of. 2, the parent child object is outside the internal references to other

  • [Transfer] Flex performance optimization project 2010-12-31

    http://nianshi.javaeye.com/blog/836432 Some knowledge of garbage collection summary: 1, deleted all references to objects in the external must be removed as a clean garbage collection system in order to be disposed of. 2, the parent child object is o

  • [Transfer] Flex Module Optimization Development 2010-12-31

    http://nianshi.javaeye.com/blog/743823 Flex Module Optimization Article Category: Flash Programming Module is basically divided into two types: 1. Complete Module, can be used by an external app - all related to the reference will be compiled into th