Reputation: 4055
I may be asking the wrong question but I am trying to add evenListeners to movieClips that are created by a method in one of my Classes.
Creating an instance of my class from the main timeline and then adding that instance to the stage.:
//MY CLASS
var createSlide:AddItems = new AddItems();
var scrollClip:Sprite = new Sprite();
addChild(scrollClip);
//ADDIMAGES CREATES 4 MOVIECLIPS
createSlide.addImages(BG,image1,image2,image3,image4);
//ADD TO STAGE
scrollClip.addChild(createSlide);
SO how do I add event listeners to the movieClips created by createSlide?
If you need more info or this is not clear just let me know.
Upvotes: 0
Views: 405
Reputation: 15338
not sure if it's what you asked, try this:
var totalChild = createSlide.numChildren-1;
for(var i:int=0;i<totalChild;i++){
var childd = createSlide.getChildAt(i);
childd.addEventListener("event type","func handler");
}
....
//ADD TO STAGE
scrollClip.addChild(createSlide);
Upvotes: 0
Reputation: 1954
I'd recommend doing it like this, because it has never failed me:
for each(var mc:MovieClip in scrollClip)
mc.addEventListener("myEvent", onMyEventHandler);
If you have other movie clips in the scrollClip and you don't want to add listeners to them only way is to add names to your added children and then iterate through them and add listeners like in my example.
Upvotes: 1
Reputation: 3522
It's hard to say without knowing what's going on inside AddItems
.
Presumably AddItems
extends Sprite
and adds the newly created objects to itself. In that case, you should be able to access them using getChildAt()
.
var child1:DisplayObject = createSlide.getChildAt(0);
var child2:DisplayObject = createSlide.getChildAt(1);
var child3:DisplayObject = createSlide.getChildAt(2);
var child4:DisplayObject = createSlide.getChildAt(3);
child1.addEventListener(...);
...
You could also expose them as public properties of the AddItems
class.
Finally, you could listen for the events within the AddItems
class itself, and dispatch them again as AddItems
own events.
Upvotes: 0