Here are some tips for flash developers, which may help them to build flash application more effectively.

So far tips listed are:

  1. Cache your Vector images – increase performance
  2. Use onEnterFrame only when needed
  3. Make movie clips invisible when alpha = 0
  4. Embed only needed symbols or fonts

Take a look and make your flash preform better 😉

1. Cache your Vector images – increase performance

When you draw any shapes and especially complex figures by actionscript (moveTo, lineTo, curveTo) and then use the drawn movie clip in animation of any kind, try setting cacheAsBitmap property to true and see the result.

2. Use onEnterFrame only when needed

If you update your movie clip in onEnterFrame handler, make sure you are doing so only when update is needed!

Usually onEnterFrame is widely used for any case when movie clip should react on external event, for example you do the flash banner displaying the sky full of stars 🙂 And the color of stars should change depending on the cursor position. One of the proper ways to implement it will be something like that:

star.onEnterFrame = function()
{
   var rgbColor:Number = getColorDependingOnCursorPosition();
   var starColor : Color = new Color (this);
   starColor.setRGB (rgbColor);
}

And this is almost true. You see onEnterFrame is called on each frame of the movie clip, and if there are 100 stars and the operations are more complex than above – you’ll have a guaranteed performance issue.

To resolve it you must add a condition check.. Here is a clue:

starMc.onEnterFrame = function()
{
  if(_global.needToRedraw == false) return;
  ...
}

We would set _global.needToRedraw to true when need all stars to change the color.. that will save a lot to you 😉

Or you may always remove onEnterFrame handler with:

delete starMc.onEnterFrame;

or

starMc.onEnterFrame = null;

3. Make movie clips invisible when alpha = 0

If you use any fade in/fade out animations for your movie clips, I would strongly recommend setting visible flag to false when faded out. In this way you will totally exclude movie clip from Flash Player rendering.

var fadeOutTween = new Tween(movieClipInstance, "_alpha", easing.Regular.easeInOut, 100, 0, 1, true);
fadeOutTween.onMotionFinished = function()
{
   movieClipInstance._visible = false
}

Or at least use removeMovieClip(), but it’s useful when the image is displayed only once, otherwise it will need to be loaded every time.

4. Embed only needed symbols or fonts

When some actions like rotations or alpha shading is required for textboxes, you will need to embed the symbols into swf. Don’t overplay with embedding, when a lot of symbols are embedded flash player behaves much slower than it should 😉 Especially if your textboxes display constant text – embed only those letters/symbols you need!

The above advices are what I meet constantly while developing flash applications. Let me know if you have any other tips or tricks. That would be really interesting to know.