Hi there,
I need a way to reference to object (or the class methods inside). I have a button “Add box” and when it is pressed it creates a new instance of class “MyBox”. The thing is everyone of these objects get the same name “box”.
Here’s a hint of what it’s like:
var arrBoxes:Array = new Array();
// var n:Number = 1;
function addBox(event:MouseEvent):void
{
var box:MyBox = new MyBox();
// var "box"+n:MyBox = new MyBox();
// n++;
factory.addChild(box);
box.name = "box"+(arrBoxes.length+1)+"_mc"; // box1_mc, box2_mc, box3_mc, ...
arrBoxes.push(box.name);
}
function changeColor(event:MouseEvent):void
{
factory.box1_mc.setColor(red); // changeColor is public function inside of "MyBox" class
// box1.setColor(red);
}
Inside of the addBox function I can easily refer to the Object with just “box” (for example box.name = …)but when in another function I cannot (and by then I might have created many "box"es).