Search code examples
actionscript-3flashswc

loading a SWC asset by variable name


I am trying to load assets from an SWC into a SWF at compile time, in as3. I'm getting the information about which assets to load from a JSON file. I can do so statically, but when I try to define the names dynamically, I'm running into problems.

So for example I can do this:

onemech[+ tmpObj.id] = new mech3 as MovieClip;

And it loads the asset named mech3. But what I would like to be able to do is something like

var mechtype:String = "mech" + mechtypenumber;    
onemech[+ tmpObj.id] = new mechtype as MovieClip;

Obviously, that doesn't work.

I looked around a bit and I found this here, which seems to be angling toward what I need, but I can't figure out how to apply what's said there to my specific situation.

For the record, I have control over both the JSON format and the naming schema within the asset SWC, if there's an easier solution there.

Thanks in advance for any assistance.


Solution

  • you just need something like this:

    var s:Class = getDefinitionByName("Symbol") as Class;
    addChild(new s());