Let your code write code for you

Using the for-in loop can help you perform similar functions/methods on a group of MovieClips all at once. As an example I had 6 MCs that I needed to attach onRelease methods to. Since all 6 MCs were themselves in the same MC I could use code like this:

for( var m:String in this) {

code here…

}

That will run through all the Objects and properties that are attached to the current MC – this.

My final code looked like this:

for(var p:String in this) {

this[p].onRelease = function():Void {
this._parent.bgSwap.gotoAndStop(this._name);
}

}