nektir
04-22-2008, 12:13 AM
I'm trying to create a reusable function with dynamic instance names.. I want to use a function that when you click on a button, it opens a pop up. But I have several buttons and several pop ups.
Here's the code I currently have:
private function openPopup(event:MouseEvent):void {
trace("Target Clicked: " + event.currentTarget.name);
this[event.currentTarget.name + "_mc"].visible = true;
this[event.currentTarget.name + "_mc"].gotoAndPlay("play");
this.stage.addChild(this[event.currentTarget.name + "_mc"]);
}
There are objects on the stage with a general instance name like "apple"... so the trace returns "apple".
Here's the non-reusable version of the code:
private function openPopup(event:MouseEvent):void {
trace("Target Clicked: " + event.currentTarget.name); //returns apple
apple_mc.visible = true;
apple_mc.gotoAndPlay("play");
this.stage.addChild(apple_mc);
}
How would I do this? I'm coming from AS2 world... so I'm not exactly sure...
Here's the code I currently have:
private function openPopup(event:MouseEvent):void {
trace("Target Clicked: " + event.currentTarget.name);
this[event.currentTarget.name + "_mc"].visible = true;
this[event.currentTarget.name + "_mc"].gotoAndPlay("play");
this.stage.addChild(this[event.currentTarget.name + "_mc"]);
}
There are objects on the stage with a general instance name like "apple"... so the trace returns "apple".
Here's the non-reusable version of the code:
private function openPopup(event:MouseEvent):void {
trace("Target Clicked: " + event.currentTarget.name); //returns apple
apple_mc.visible = true;
apple_mc.gotoAndPlay("play");
this.stage.addChild(apple_mc);
}
How would I do this? I'm coming from AS2 world... so I'm not exactly sure...