Optimizing your Flash SWFs (part 1)
Nowadays there is a lot less reasons to spend hours optimizing our Flash content for speed because computers are faster and cheaper to buy than 10 years ago. This doesn't mean that we should stuff our flash files with assets without worrying about optimization.
There is a couple of good tricks that will tend to improve the speed and the general performance of Flash files on older and not so old systems.
General optimization
General
- Use symbols, animated or otherwise, for every element that appears more than once.
- When creating animation sequences, use tweened animations, whenever possible. These animations use less file space than a series of keyframes.
- For animation sequences, use movie clips instead of graphic symbols.
- Limit the area of change in each keyframe; make the action take place in as small an area as possible.
- Avoid animating bitmap elements; use bitmap images as background or static elements.
For sound, use MP3, the smallest sound format, whenever possible.
Lines and elements
- Group elements as much as possible.
- Use layers to separate elements that change during the animation from those that do not.
- Use Modify > Curves > Optimize to minimize the number of separate lines that are used to describe shapes.
- Limit the number of special line types, such as dashed, dotted, ragged, and so on. Solid lines require less memory. Lines created with the Pencil tool require less memory than brush strokes.
Text and fonts
- Limit the number of fonts and font styles. Use embedded fonts sparingly because they increase file size.
- For Embed Fonts options, select only the characters needed instead of including the entire font.
Colors
- Use the Color menu in the Symbol Property inspector to create many instances of a single symbol in different colors.
- Use the Color Mixer (Window > Color Mixer) to match the color palette of the document to a browser-specific palette.- Use gradients sparingly. Filling an area with gradient color requires about 50 bytes more than filling it with solid color.
- Use alpha transparency sparingly because it can slow playback.
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++) {
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 setInterval() function).
- Add the var keyword when declaring a variable.
- Don't use class variables or global variables when local variables will suffice.
Saturday, August 14, 2010
Subscribe to:
Post Comments (Atom)
1 comment:
very bood blog
Post a Comment