PDA

View Full Version : Optimizing Tricks


ryan.m
11-02-2005, 09:27 PM
Please List the best techniques for optimizing in flash
Also best ways to reduces total file size for bitmaps that are imported from illustrator in to flash

oka_
11-02-2005, 09:30 PM
This is a pretty good tutorial for code optimization;
http://gotoandplay.it/_articles/2004/01/as_optimizations.php

senocular
11-02-2005, 10:44 PM
http://www.nowrap.de/flasm.html

jsebrech
11-03-2005, 07:20 AM
Things that I've found to work for me when optimizing that are specific to flash:
- limit function calls (they're way too expensive)
- if you need an object to carry data, instead of make it a class instance (created using a constructor, which is a function call) make it an anonymous object (replacing a Point class with anonymous objects made a huge difference for me)
- use "for (var index in array)" notation whenever possible
- use short variable names, one or two letters (made a 15 percent speed difference in some tight loops of mine). This messes with readability and maintainability though, so you will want to use this sparingly and comment that code extensively.
- limit movieclip creation (it's often worth it to write additional code to combine the content of multiple movieclips into one)
- in classes, declare commonly used method variables from methods that don't call each other as private members of the class instead of declaring them inside the methods
- create shorthands for commonly used variables or functions from another object. For example, if you use Math.cos a lot, create a variable cos like this: var cos = Math.cos, then replace all the Math.cos calls with just cos. This works for classes you create as well. I had a class that contained constants, and by shorthanding those in some tight loops I gained a noticeable speed boost.

In general though, before you make your retreat to any of these tips, I would advise thinking carefully about your code, and how you could optimize it. Optimizing your data structures and your algorithms makes a way bigger difference than using any flash-specific hacks.