Name / concatenation of a dynamic instance of flash as3

I have an array of project code types, for example:

project_types_array[0] = "p"
project_types_array[1] = "exp"

and etc.

and the corresponding set of video clips exported for actionscript, with names:

type_p
type_exp

and etc.

I want to somehow dynamically attach a movie clip on the stage according to the type of project that exists in the array. I could just do something like this:

for ( var i in project_types_array) {
    if (project_types_array[i] == "p"){
        var clip_p = new type_p();
        container.header.type_loader.addChild(clip_p);
    }
}

but I would rather do something like this:

for (var I'm in project_types_array) {

var "clip_" + project_types_array[i] = new "type_" + project_types_array[i]();
container.header.type_loader.addChild("clip_"+project_types_array[i]);

}

How do I achieve this?

+3
source share
1 answer

try

var c:Class = getDefinitionByName('type_' + project_types_array[i]);
var spr:c = new c();

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/package.html#getDefinitionByName%28%29

+3
source

Source: https://habr.com/ru/post/1793078/


All Articles