In the event of making new children, especially like library movieclips, you could create a generic function that receives the class reference for the movieclip you wish to create. For the below example, let’s say in your library is a RedBox linked movieclip with a variety of other movieclips like it that all need to be created the same way:

addChild( create(RedBox) );

function create(ObjectType:Class):MovieClip{
  // Adding "as MovieClip" tells Flash that ObjectType will be
 // some kind of MovieClip derived class.
  var newMC:MovieClip = new ObjectType() as MovieClip;
  // Add new event listeners to newMC
  // Add logic or variable settings like X and Y
  // returns the newMC to be added to the stage.
  return newMC;
}

The benefit is you can dynamically create objects that all get setup the same way… the function does not care what type of movieclip needs to be created just as long as it’s a type of movieclip.


Author: Jonathan Dunlap
Jonathan is an experienced software engineer, sole blogger of JADBOX, author of FlashMVC, humanitarian, and has contracted work for Microsoft, Coke, and Disney.
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • email
  • Furl
  • LinkedIn
  • Pownce
  • Reddit
  • StumbleUpon
  • TwitThis
Auto-Generated Related Posts:
  1. Countdown to Mobile Flash Player 10...

Tags: ,