3

I have an array of project type codes like this:

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

etc.

and a corresponding set of movie clips, exported for actionscript, with names:

type_p
type_exp

etc.

I want to somehow dynamically attach a movieclip on the stage according to the project type 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'd rather do something like this:

for ( var i 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?

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

3 Comments

If I try this - I get the following errors: Type was not found or was not a compile-time constant: typeClass. Implicit coercion of a value with static type Object to a possibly unrelated type Class.
@mheavers - where are the clips stored?
the clips are in my flash library and given a class name at runtime, and attached from the library. Does that answer your question www0z0k

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.