0

i have a small problem with loading specific images in flash...

In my project I want to load a certain image from the library (f.ex. "event1_pic.jpg") - the actual number is stored in an int variable.

I already exported the jpg for actionscript and it works fine when i directly call the image by its full name...

That's the current working solution (calling the full name of the image) :

var event_pic = new event1_pic();
bmp = new Bitmap(event_pic);
addChild(bmp);

My attempt on integrating the int variable in the name (event_number=1):

var event_pic = new this["event"+event_number+"_pic"]();
big_pic = "event"+event_number+"_pic";
var event_pic = new this.big_pic();  

Can anyone please help me with that problem? Or maybe anyone knows another solution on loading specific images that only differ in name?

Infaust
  • 11
  • 3
  • 1
    [Look into getDefinitionByName](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/package.html#getDefinitionByName()) What you are attempting at the moment is to access a reference, but what you should do is to access a Class. –  Jun 29 '15 at 08:54
  • See linked question on how to use `getDefinitionByName()`, and yes, you can use dynamic strings with this. – Vesper Jun 29 '15 at 09:27

1 Answers1

0

As mentioned in the comments, you can use flash.utils.getDefinitionByName() like this :

for(var i:int = 0; i < n; i++){
    var mc:MovieClip = new (flash.utils.getDefinitionByName('my_class_' + i) as Class);
    addChild(mc);
}

Or using loaderInfo.applicationDomain.getDefinition() :

for(var i:int = 0; i < n; i++){
    var mc:MovieClip = new (this.loaderInfo.applicationDomain.getDefinition('my_class_' + i) as Class);
    addChild(mc);
}

Hope that can help.

akmozo
  • 9,829
  • 3
  • 28
  • 44