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.
Don't 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()
Often, setting the local reference once is preferable and more efficient.
Assign the
Array.length
Assign
Array.length
itself. For example,
myArr.length
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
function).
setInterval()
Add the
keyword when declaring a variable.
var
Don't use class variables or global variables when local variables will suffice.
function or array access operator.
to a variable before a loop.
to a variable before a loop to use as its condition, rather than using
ActionScript and Flash Player optimization
763
Need help?
Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?