0

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?

Devin Burke
  • 13,642
  • 12
  • 55
  • 82
user997379
  • 25
  • 1
  • 5
  • Where is i defined? What value are you expecting it to reference? Can you show your full loop? 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 need a reference to the image, you can use e.target in your handler function. – JeffryHouser Jan 02 '12 at 17:58
  • I'll post it as a formal answer, then. – JeffryHouser Jan 02 '12 at 19:45

1 Answers1

0

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.target in your handler function.

JeffryHouser
  • 39,401
  • 4
  • 38
  • 59