-
[RESOLVED] problem with array of movie clips
hi
I've got a bunch of movie clips on the stage, and I am trying to apply the same function (adding the same event listener) for each of them when they're clicked.
I did this by setting up an array for the clips, (which the nice cancerinform told me how to do).
However, now only movie clip that is responding to the click is the last one in the array
PHP Code:
/* LISTEN FOR CLICKS ON THE THUMBS */ var thumbs:Array = new Array("mc1","mc2","mc3");
for (var i:int = 0; i < thumbs.length; i++) { var thumb:MovieClip = getChildByName(thumbs[i]) as MovieClip; } thumb.buttonMode = true;
thumb.addEventListener(MouseEvent.CLICK, thumbClickHandler);
/* FUNCTION FOR CLICKS ON THE THUMBS */
function thumbClickHandler(evt:MouseEvent):void {
//function in here
}
Any ideas anyone? (much appreciated!)
-
You need to move your thumb manipulation code inside the loop. What you're doing now is running through all the thumbs, setting thumb to each. When that's done, thumb is on the last one, then you start doing useful stuff to it.
Code:
/* LISTEN FOR CLICKS ON THE THUMBS
*/
var thumbs:Array = new Array("mc1","mc2","mc3");
for (var i:int = 0; i < thumbs.length; i++) {
var thumb:MovieClip = getChildByName(thumbs[i]) as MovieClip;
thumb.buttonMode = true;
thumb.addEventListener(MouseEvent.CLICK, thumbClickHandler);
}
/* FUNCTION FOR CLICKS ON THE THUMBS
*/
function thumbClickHandler(evt:MouseEvent):void {
//function in here
}
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|