Learning ActionScript 2.0 in Adobe Flash |
|
|
|
| Best Practices and Coding Conventions for ActionScript 2.0 > ActionScript and Flash Player optimization > Optimizing your code | |||
Remember the following guidelines when you optimize your code:
It is better to include the contents of a small function inside the loop.
Native functions are faster than user-defined functions.
Data-type annotations should be precise, because it improves performance. Use the Object type only when there is no reasonable alternative.
eval() function or array access operator.
Often, setting the local reference once is preferable and more efficient.
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]);
}
Flash Player spends a lot of time processing loops (such as those that use the setInterval() function).
var keyword when declaring a variable.
|
|
|
|