Easy AS3 Tips For Conserving CPU In The Flash Player
Easy AS3 Tips For Conserving CPU In The Flash Player
1. Math.floor
can be unnecessary.
Using uint to round any numbers with a decimal is much more efficient. For example:
var val = uint( xpos * len);
2. Multiplication is faster than dividing.
I had no clue about this one, but for some reason Flash Player is more up on it's multiplication tables than division. So if you have alot of division tasks, you can turn them to multiplication by taking the inverse of what you are dividing by. If you just had some horrid flashbacks of grade school math class, here's an easy one:10 / 2 is the same as 10 * .5
3. Object and array literals are cooler than using the new keyword operator.
Using New Operator:
var arr:Array = new Array();
Object Literal:
var arr:Array = [];
Fancy schmancy!
4. It's like second nature to automatically create MovieClips.
Ask yourself, will this display object use the timeline? If not, then create a Sprite instead of MovieClip.5. Shapes are even lighter than Sprites.
Who knew? But if you don't need mouse interaction or nest any child display objects, then knock your socks off and create a Shape.6. Apparently it's more efficient to place conditional statements that are more likely to render true first within your block.
I have no clue why — but check out step 14 in Patrick Jaoko's tutorial.
7. Using mouseEnabled
and mouseChildren
can save your life.
Not really, but if a display object doesn't require any user interaction, let it go. There's many more and are all explained in depth. Check out the tutorial.