This is one of my old posts, but it seems people liked it, so here it is again:
The list below is some of my own “learned by doing” tips and some tips I have seen elsewhere – I cannot give guarantees to their effect on your projects. Some of them apply to both AS2 and AS3, some of them don’t!
1. Use scrollrect instead of masks – masks only hides pixels from us, not from Flash!
2. Framerates are never “magical” – the old 31 fps doesn’t apply anymore.
3. Decide framerates from project to project – framerates are often between 25 and 40, sometimes you want to push it further, but remember it pulls energy from the computer running the swf.
4. Use cacheAsBitmap on vector graphics – but don’t do it if the object is scaled or rotated.
5. Take screenshots/snapshots of complex movieclips and sprites – use the Bitmap stuff available in Flash, then just animate one object instead of many!
6. Always – ALWAYS clean up eventlisteners and onEnterFrame functions – they are slowing down your computer if you don’t!
7. If your framerate can’t keep up, a small trick is to put an empty mp3 on the timeline – it should force Flash to skip frames to keep up with the sound.
8. Use visible = false instead of alpha=0
9. Remember that garbage collection is tricky – always try to use weak references, removeChild and removeEventListener.
10. Use round mouse coordinates.
11. Recycle your movieclips instead of creating new ones.
12. Expo (in some tweening engines) is the best performer – read this somewhere, but have no prove.
13. Remove trace() from your code when you are done using them.
14. Set cacheAsBitmap on dynamic textfields – if you have timeline animations.
15. onEnterFrame is supposedly better than onMouseMove and Stage.onResize – because it only updates to the max of your framerate.
16. Filters work best in powers of 2 – 2, 4, 8 , 16, 32, 64… this is a fact, even in the Flash documentation.
17. Optimize your loops – by saving the length of an array into a variable, like this:
var len:int = myArray.length;
for(var i:int = 0; i < len; i++)
18. Use int instead of numbers and uint in loops.
19. Always strict data type variables.
4 Comments
Also check out this link:
http://dispatchevent.org/mims/as3-performance-comparison-tool/
Hi Michael,
It’s me from flash-design.dk. You left me some input on the flash forum. I just noticed you have a blog, so I couldn’t resist not posting. Thanks for all your helpful tips in this post. A lot of them I learned myself over the years but some of them I haven’t thought of, so very useful.
Thanks
Also check out:
http://www.gskinner.com/blog/archives/2006/11/understanding_d.html
http://rockonflash.wordpress.com/2007/08/07/mouse-events-on-drawnhidden-objects/
Hi there,
about that eventListeners… I wrote an Event Listener Manager (ELM) – a static class which makes your life easier working with them. It features grouping, listing, profiling, removeAll, removeGroup, remove all clicks, showAll and since 1.20 autoremove and much more – check wiki’s API page.
http://code.google.com/p/as3listenermanager/
it’s open-source – have fun
michael