Tuesday, December 04, 2007

Watch out for a closure in a loop:

var info = [ "a", "b", "c", ... ];
for (var i = 0; i < 10; i++)
{
var str:String = info[i];
btn[i].onRelease = function() { getURL(str) }
}

All buttons will bring you to the last url because the closure maintains a reference to the variable str.

Dynamically loading images/swf + masking

When you are loading an image into an empty movieclip, beware of doing setMask on the mc too early. Try to do everything after the image is done loading. In fact, masking is only one of the operations that can fail when applied prematurely.