EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 763

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
ActionScript and Flash Player optimization 763
Optimizing your code
Remember the following guidelines when you optimize your code:
Avoid calling a function multiple times from within a loop.
It is better to include the contents of a small function inside the loop.
Use native functions when possible.
Native functions are faster than user-defined functions.
Dont overuse the Object type.
Data-type annotations should be precise, because it improves performance. Use the
Object type only when there is no reasonable alternative.
Avoid using the eval() function or array access operator.
Often, setting the local reference once is preferable and more efficient.
Assign the Array.length to a variable before a loop.
Assign
Array.length to a variable before a loop to use as its condition, rather than using
myArr.length itself. For example,
var fontArr:Array = TextField.getFontList();
var arrayLen:Number = fontArr.length;
for (var i:Number = 0; i < arrayLen; i++) {
trace(fontArr[i]);
}
instead of:
var fontArr:Array = TextField.getFontList();
for (var i:Number = 0; i < fontArr.length; i++) {
trace(fontArr[i]);
}
Focus on optimizing loops, and any repeating actions.
Flash Player spends a lot of time processing loops (such as those that use the
setInterval() function).
Add the var keyword when declaring a variable.
Dont use class variables or global variables when local variables will suffice.

Table of Contents

Related product manuals