I dynamically create images in a loop (flash builder 4.5) and when I set mouse click event, I’m using this:
image.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void{fromThumbnail(e,i)});
to pass i. However, when I click on any image, the function thumbnail prints the last i.
Is there solution for this problem?
If ‘i’ is an instance variable, then
fromThumbnail(e,i);will always pass the current value of the instance variable; with no consideration for what the value was when you added the event listener to the image.If you’re trying to reference the image that you added the listener on, then you could use
e.targetin your handler function.