Tips for optimizing ActionScript in Adobe Flash movies
If speed is a primary concern, look at the visual aspects of the site. In most cases the majority of speed bottlenecks occur when attempting too many (or too complicated rendering tasks.) Optimizing the visual can achieve significantly greater gains than a slight improvement in code processing.
For optimization tips, see Streaming and file optimization techniques for Flash Player.
Some items to consider:
| When possible, try not to manipulate long strings. Break the strings up into small pieces, run the string operations and concatenate the result into a final string for output. The smaller the string the faster the operation will complete.
This should also be a consideration with incoming XML data. Large amounts of XML should be broken up before loading into Macromedia Flash if possible. |
|
| If manipulating a lot of data on the client, consider using the server to pre-filter the data that the client actually sees.
Server side processing will be faster, eases the processing burden on the Macromedia Flash Player (and the viewer's CPU), and will become increasingly important as the audience for low-memory portable devices, such as PDA's and cell phones, increases. |
|
| Avoid lengthy scripts that may prevent the user from interacting with the content. If it's necessary to process a lot of information, considering breaking the processing into chunks and distributing the task across a series of frames.
One frame can do the initial calculation, set up the necessary variables, then finish processing and rendering the visuals. In the next frame pick up those variables, perform more calculation, then again allow the frame to process and render. This type of "distributed processing" may be more difficult to write and debug, but will insure a more consistent experience for your users. On a similar note, there may be simple scripts that are being evaluated on every frame. Consider if it might be possible to run these scripts once, save their results and call them when needed instead of rerunning the script every time. |
|
| If you're controlling a large number of movie clip instances using ActionScript, consider how many times you might be repeating the same routines or resetting the same variables.
Can that information be broken out into a single custom Function? Is it possible to use a function to calculate that information once and pass it back to the clip instances instead of processing the function multiple times? For Function details, see the definition of Function in the online Flash Dictionary |
|
| In some cases, it may be possible to achieve faster script processing by using deprecated Macromedia Flash 4 ActionScript syntax. This might achieve an immediate goal of faster code processing, but keep in mind that deprecated syntax is deprecated for a reason.
There is no guarantee that the underlying mechanisms used to achieve that speed will be around in the next revision of the Flash Player, and an extensive recoding might be necessary. Note:Macromedia Flash Player 6 includes significantly improved ActionScript performance, eliminating virtually all the circumstances in which it would be necessary to use Macromedia Flash 4 ActionScript syntax. |
|
| Bitmaps are fixed-resolution images. They look best when one pixel of source imagery exactly matches one pixel of screen display. Because SWF streams and scales, it's rare to have this type of one-to-one correspondence.
This means you're asking the computer to create new screen pixels from groups of source pixels and draw them onscreen every time the playback moves to a new frame. Bitmap-heavy projects can be slower to redraw because of this. Make use of vectors and bitmap fills whenever possible to avoid this. Also, it may seem simple to mention it, but any item used more than once in the SWF should be inside a symbol. This includes bitmaps, imported vector art and art created in Flash. |
|
| Looping: tight loops can be problematic. Give the player a chance to break out of the loop so it can process other actions. | |
| Minimize simultaneous streaming whenever possible. Multiple streams cost processing power and bandwidth.If multiple streams of audio are necessary or multiple SWF's must be loaded, use a preloading technique at the beginning of the movie.
This costs more time up front, but at that point it's possible to let the viewer know that something is happening. Later in the movie a lag might be interpreted as a system problem or may lose the viewer's attention. |
This content requires Flash
To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.
Download the free Flash Player now!
