By Kshitiz Gupta



18 May 2012

Within this article, I will enlist some of the simple optimizations that one can do within actionscript 3 and particularly iOS mobile applications.
1) No modifications to display list within timer events
In case you have a timer event firing at a very high rate and your application is making changes to the display list within this event handler. Consider that the fps of your application is lesser than the rate at which your timer is firing. In such a case you will be making changes to the display list which will never be actually used and you will be making unnecessary calculations within these timer events slowing down the player.
Instead the recommendation in such a case is to use stage.invalidate() call and use the RENDER event. In case you have a very deep display list, do not commit changes directly to the display list instead hold the changes in temporary variable and once you feel that sufficient changes have been made to the display list, then call stage.invalidate(). This will cause a RENDER event to get fired. One should use this event to make changes to the display list from the temporary variables which were holding these changes.
2) Keep constructors small
Constructor code is not JIT and is interpreted because of which it runs slow. Avoid having large constructors. In case of iOS however constructors are AOT (Ahead of time) compiled so this issue makes no difference for iOS.
3) Image handling
As a general rule of thumb, avoid embedding images and load them only on runtime when needed. Loading images at runtime results in a little more complicated code but if start up time is the requirement then definitely go for loading images at runtime rather then embedding them as part of swf.
4) Image formats
This is a general guidance and not related to actionscript 3. In case you are using a small image (lets say something around 10 x 10 image) then one should a png image. If the image is that of a face or something that has a lot of textures then definitely use jpg images. Obviously, if you need transparency in your images then you have no choice but to use png images.
5) Image sizes
It is important to use right sized images when making mobile applications. Working with large image sizes can be catastrophic to fps. If your rendermode is gpu and if you are using a mac then make sure that you check gpu utilization. This is provided by the open gl es driver tool in instruments. If the shader utilizations are coming in at 100%, then take it is as a hint to reduce image sizes.
Do visit for similar optimizations you can do for your applications