So I have an array of movieclip instances. I need to loop through the array and add an event handler for each instance. Then on click I need to call a function and pass that instance into a function (Which is why I had originally made that other thread).
So in AS.2 I was able to do something like this:
for (var j:Number = 0; j < menuItems.length; j++) {
mc = menuItems[j];
mc.id = j;
mc.onRelease = function ():Void {
someFunction(this.id);
};
}
Inside my someFunction this.id would trace the movieclip instance that was clicked.
Now in AS 3 I’m having some trouble
So inside my constructor I have
for (var i:Number = 0; i <= thumbs.length; i++) {
mc = thumbs*;
mc.id = i;
trace(mc.id);
}
Where mc datatype is a movieclip and id is a number
I get this error
TypeError: Error #1034: Type Coercion failed: cannot convert "imgThumb0" to flash.display.MovieClip.
Should probably be something like this if I understood you correctly.
Btw, you should look into using Sprites. I had that same woe when I was migrating, but sprites are both faster and more memory efficient than movieclips.
anyway;
package {
import flash.display.MovieClip;
public class Sample extends MovieClip {
private var thumbs:Array = [];
public function Sample(){
var mc:MovieClip;
for (var j:Number = 0; j <= 13; j++){
mc = new MovieClip();
mc.id = j;
mc.name = "imgThumb"+j;
thumbs.push(mc);
}
}
}
}
So this issue is that I’m trying to pass the mc.name into another function. The problem is it’s always passing imgThumb13 because that’s the last item in the array
for (var j:Number = 0; j <= 13; j++){
mc = new MovieClip();
mc.id = j;
mc.name = "imgThumb"+j;
thumbs.push(mc);
editSpreadClip[mc.name].addEventListener(MouseEvent.MOUSE_DOWN, function(event:MouseEvent):void {
loadImage(mc.name);
});
}