Copy link to clipboard
Copied
I'm adding movieclips from a library (topicElement is its class instance name) and I'd like to go to frame 2 of one of the movieclips. Here's my code:
if (topicNew == topicOld) {
topicHolder.addChild(topicElement);
topicHolder.getChildAt(i) as MovieClip;
topicHolder.getChildAt(i).gotoAndStop(2);
//the following also didn't work, no errors, but nothing happens on the stage
//var mc:MovieClip = topicHolder.getChildAt(i) as MovieClip;
//mc = new MovieClip();
//mc.gotoAndStop(2);
}
What do i have to do to be able to access objects from my library as movieclips?
Copy link to clipboard
Copied
What code are you using to add these movieclips from the library?
Copy link to clipboard
Copied
A give it a class linkage in the library and then create a new instance of this class and add it to the stage, but whenever I do this I cannot animate the object.
Copy link to clipboard
Copied
I think you're getting the error for several reasons. First off, I don't think you're referencing the correct object. What I mean is, it looks like you're trying to retreive whatever object is at index location "i". Usually, whenever you add an object, it goes to the top of the layer. So your "i" may not be the correct index. Also, I don't think that you have associated the object that you want to add to your MovieClip with a class name (ActionScript Linkage). In order to reference an object from the Library, you have to assign a Class name in either the Symbol Properties window or the Linkage tab in the Library.
Here's one way that you can access an object from your library. This approach assumes that you've linked your object with a name, such as 'topicElement_obj' for example.
if (topicNew == topicOld) {
//Declare a new instance of the object 'topicElement_obj'
var topicElement:topicElement_obj = new topicElement_obj();
//Add the object to the topicHolder MovieClip
topicHolder.addChild(topicElement);
//Go to the second frame
topicElement.gotoAndStop(2);
}
Copy link to clipboard
Copied
If your library symbol has a base class of MovieClip, the code ought to work (other than issues to do with the i variable Dominique mentioned). If you're not sure, or if you want to make sure that it's a movieclip, you can do what you have in your commented out lines. But do them in the right way. This should work:
var mc:MovieClip = new topicElement() as MovieClip;
addChild(mc);
mc.gotoAndStop(2);