PDA

View Full Version : [AS3] Adding a MovieClip to the Stage from a Class function


darthjones
12-28-2008, 03:39 PM
Of course, it's easy enough to do when not working with classes. Basically, I want to be able to execute a function from one of my classes that does the following -

function buildArea():void
{
var i:Number = 1;
this[ "tile_" + i ] = new TileSet01(); // a for-loop will be used later, so this is necessary
addChild( this[ "tile_" + i ] );
}

buildArea();
If I remember correctly, I did this in AS2 using Delegates. Unfortunately, it doesn't seem to work the same way in AS3...

rawmantick
12-29-2008, 04:07 AM
for( var i:int=0 ; i<10 ; i++ )
{
var tileSet:MovieClip = new TileSet01();
tileSet.name = "tileset_"+i;
addChild(tileSet);
}

//and then access:
trace(this["tileset_7"]);