Social Icons

twitterfacebooklinkedinbehancerss feedemail

Friday, May 4, 2012

Easy AS3 Tips For Conserving CPU In The Flash Player

Easy AS3 Tips For Conserving CPU In The Flash Player

A really good tutorial by Patrick Jaoko published on ActiveTuts+ broke down the code of a bloated particle system and then step by step detailed what can be done to increase the speed and overall performance of the SWF. It was amazing to see how some of the littlest tweaks shown a big difference in CPU. The before and after results are worth checking out. Here are a few of the most basic tweaks he employs — some of which I never thought about but are good to know.

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.

No comments:

Post a Comment



What We Do...

Queens Web Design and Graphics is a web and graphic design company in Queens, NY specializing in providing local businesses with affordable websites offering design, animation and multimedia services. Learn More...