0

i'm porting an old AS2 project to AS3, And have encounter a problem. I've tried a few different things but had no success.

in AS2 when dynamically attaching a MC from the library i would sometimes use an array. the array would hold linkage reference's, like so;

var mc:String = state_ar[currentState];
this.container.attachMovie(mc,mc,this.getNextHighestDepth());
targetMC = this.container[mc];

How would i do this in AS3?

3 Answers 3

2

You would do that using getDefinition() or getDefinitionByName()

Check out this answer for code, your situation sounds quite similar.

Note: The only difference is you might be using MovieClips, not images, so you won't need the 0,0 arguments in the constructor.

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

Comments

1

I'm not quite sure if this is what you're asking but I'll give it a shot.

//New array to store Movie Clips references    
var myArray:Array = new Array();
//Create a movie clip
var movieClip:MovieClip = new MovieClip();
//Add it to the array for reference
myArray.push(movieClip);
//Put it on the stage
this.addChild(movieClip);

You can still use arrays to store references to an object and you can reference them directly.


In as3 the MovieClips in the library will have a class name, so if you have a MC in the library called MyMovie you would add it in as3 with:

var myMovie:MyMovie = new MyMovie();
addChild(myMovie);

3 Comments

sorry, i didn't explain myself very well. the array was used to store (what were called in AS2) linkages. for example; i have 3 different movieClips in my library, each with there own different linkage id. i create an array; state_ar = ['link_1','link_2','link_3']; then reference an index from the array; var linkageID:String = state_ar[0], then attach the movie; attachMovie(linkageID,linkageID, this.getNextHighestDepth()).
As3 is object oriented so you create and add movieclips by instancing them see my edited code. Hope that helps.
thanks for your response TripWired, but the question refers to something else.
1

Answer;

var mc:String = state_ar[currentState];
var classReference:Class = getDefinitionByName(mc) as Class;
var tempMC:Object = new classReference();
this.container.addChild(tempMC)

Thanks George

Comments

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.