Showcase and discover digital art at yex

Follow Design Stacks

Subscribe to our free newsletter to get all our latest tutorials and articles delivered directly to your inbox!

ActionScript and Flash Player Optimization

ActionScript and Flash Player Optimization

If you compile a SWF file that contains ActionScript 2.0 with publish settings set to Flash Player 6 and ActionScript 1.0, your code functions as long as it does not use ActionScript 2.0 classes. No case sensitivity is involved with the code, only Flash Player. Therefore, if you compile your SWF file with Publish Settings set to Flash Player 7 or 8 and ActionScript 1.0, Flash enforces case sensitivity.

Data type annotations (strict data types) are enforced at compile time for Flash Player 7 and 8 when you have publish settings set to ActionScript 2.0.

ActionScript 2.0 compiles to ActionScript 1.0 bytecode when you publish your applications, so you can target Flash Player 6, 7, or 8 while working with ActionScript 2.0.

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() 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++) {

    instead of:

    var fontArr:Array = TextField.getFontList();
    for (var i:Number = 0; i < fontArr.length; 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.
  • Don’t use class variables or global variables when local variables will suffice.