Log In  
 
  Welcome  

Optimizing [ActionScript]

?

Add your own tips

Sign into this wiki (or register) then use Edit to insert your tip or click Add Comment at the bottom of the page.

 Keep code simple 

  • Remove unused movie clips, delete unnecessary frame and code loops, and avoid too many frames or extraneous frames.

Author: Adobe

Rate this tip?

 Avoid FOR loops

  • Using FOR loops can be expensive because of the overhead incurred while the condition is checked with each iteration. When the costs of the iteration and the loop overhead are comparable, execute multiple operations individually instead of using a loop. The code may be longer, but performance will improve.
    Stop frame-based looping as soon as it is no longer needed.

Author: Adobe

Rate this tip?

 Avoid string/array processing

  • When possible, avoid string and array processing because it can be CPU-intensive.
    ?

Author: Adobe

Rate this tip?

 Accessing properties directly

  • Always try to access properties directly rather than using [ActionScript];getter and setter methods, which have more overhead than other method calls.

Author: Adobe

Rate this tip?

 Manage events wisely

  • Keep event listener arrays compact by using conditions to check whether a listener exists (is not null) before calling it. Clear any active intervals by calling clearInterval, and remove any active listeners by calling removeListener before removing content using unloadapplication or removeapplicationClip. Flash does not re-collect SWF data memory (for example, from intervals and listeners) if any [ActionScript] functions are still referring to the SWF data when a movie clip is unloaded.

Author: Adobe

Rate this tip?

 Delete variables

  • When variables are no longer needed, delete them or set them to null, which marks them for garbage collection. Deleting variables helps optimize memory use during run time, because unneeded assets are removed from the SWF file. It is better to delete variables than to set them to null.

Author: Adobe

Rate this tip?

 Remove listeners

  • Explicitly remove listeners from objects by calling removeListener before garbage collection.

Author: Adobe

Rate this tip?

 Use call instead of apply 

  • If a function is being called dynamically and passing a fixed set of parameters, use call instead of apply.

Author: Adobe

Rate this tip?

 Make namespaces compact

  •  Make namespaces (such as paths) more compact to reduce startup time. Every level in the package is compiled to an IF statement and causes a new Object call, so having fewer levels in the path saves time. For example, a path with the levels com.xxx.yyy.aaa.bbb.ccc.funtionName causes an object to be instantiated for com.xxx.yyy.aaa.bbb.ccc. Some Flash developers use preprocessor software to reduce the path to a unique identifier, such as 58923409876.functionName, before compiling the SWF code.

Author: Adobe

Rate this tip?

 Reuse ActionScript for multiple SWFs 

  • If a file consists of multiple SWF files that use the same [ActionScript];classes, exclude those classes from select SWF files during compilation. This can help reduce file download time and run-time memory requirements.

Author: Adobe

Rate this tip?

 Avoid using Object.watch 

  • Avoid using Object.watch and Object.unwatch, because every change to an object property requires the player to determine whether a change notification must be sent.

Author: Adobe

Rate this tip?

 Split up code 

  • If [ActionScript];code that executes on a keyframe in the timeline requires more than 1 second to complete, consider splitting up that code to execute over multiple keyframes.

Author: Adobe

Rate this tip?

 Remove trace statements

  • Remove trace statements from the code when publishing the SWF file. To do this, select the Omit Trace Actions check box on the Flash tab in the Publish Settings dialog box.

Author: Adobe

Rate this tip?

 Avoid inheritance 

  • Inheritance increases the number of method calls and uses more memory: a class that includes all the functionality it needs is more efficient at run time than a class that inherits some of its functionality from a superclass. Therefore, you may need to make a design trade-off between extensibility of classes and efficiency of code.

Author: Adobe

Rate this tip?

 Delete custom classes

  • When one SWF file loads another SWF file that contains a custom [ActionScript];class (for example, foo.bar.[CustomClass]) and then unloads the SWF file, the class definition remains in memory. To save memory, explicitly delete any custom classes in unloaded SWF files. Use the delete statement and specify the fully qualified class name, such as: delete foo.bar.[CustomClass].

Author: Adobe

Rate this tip?

 Limit the use of global variables 

  • Because they are not marked for garbage collection if the movie clip that defined them is removed.

Author: Adobe

Rate this tip?

 Avoid using the standard user interface components  

  • Avoid using the standard user interface components (available in the Components panel in Flash). These components are designed to run on desktop computers and are not optimized to run on mobile devices.

Author: Adobe

Rate this tip?

  Avoid deep nesting

  • Whenever possible, avoid deeply nested functions.

Author: Adobe

Rate this tip?

 Avoid referencing nonexistent variables, objects, or functions

  • Compared to the desktop version of Flash Player, Flash Lite 2 looks up references to nonexistent variables slowly, which can significantly affect performance.

Author: Adobe

Rate this tip?

 Avoid anonymous syntax

  • Avoid defining functions using anonymous syntax.

Author: Adobe

Rate this tip?

 Minimize the use of Math functions and floating-point numbers

  • Calculating these values slows performance. If you must use the Math routines, consider precalculating the values and storing them in an array of variables. Retrieving the values from a data table is much faster than having Flash calculate them at run time.

Author: Adobe

Rate this tip?

   



Added by Erick Vera , last edited by Erick Vera on Apr 26, 2007  (view change)
Labels: 

Powered by Atlassian Confluence 2.7.1, the Enterprise Wiki. Bug/feature request - Atlassian news - Contact administrators