Let your code write code for you

September 3rd, 2006 . by polyGeek

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);

}

}

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • Digg
  • Facebook

Leave a Reply

Name

Mail (never published)

Website

- Why ask? This confirms you are a human user!

   




© Copyright 2008 polyGeek.com / Dan Florio, All Rights Reserved Except Where Explicitly Stated
Web Developement Blogs - Blog Catalog Blog Directory
M2 Websites