Below is my AS3 code:
public function load_swfs(event:Event)
{
var loader:Loader = event.target.getChildAt(0) as Loader;
var mc:MovieClip = loader.content as MovieClip;
var mc_name = 'somethingGeneratedElsewhere';
this.animations[mc_name] = mc;
}
// --------------------------------------------------------------------
public function add(mc_name)
{
//this.animations is a object that holds a bunch of dynamically loaded SWF files.
addChild(this.animations[mc_name]);
this.animations[mc_name].addEventListener(Event.ENTER_FRAME, enter_frame_handler);
}
// --------------------------------------------------------------------
public function enter_frame_handler(e:Event)
{
//how do I get mc_name in this function
// Example, if I run add('movie123'). How do I get 'movie123' in this function?
}
If I run add(‘movie123’). How do I get the string ‘movie123’ in the enter_frame_handler function?
UPDATE
This forum post (Click Here) describes the issues I am having but doesn’t provide the solution I am looking for. Luckily @kapep provided a simple solution that solved the issue.
The other solutions are usually the better options. If you can’t dynamically add properties, you still could map the objects to the names using a Dictionary.
Anyway, keep in mind that
this.animations[mc_name]isn’t really using the movieclips name and that it isn’t possible to get the variable name that way. If you would dothis.animations[some_other_name] = this.animations[mc_name];you would have two variables referring to the same object. There would be no way to tell which variable got used to attach the listener to. So make sure you understand the difference between a movieclip name and it’s variable’s name.