图像的鼠标事件
我在循环中动态创建图像(flash builder 4.5),当我设置鼠标单击事件时,我使用这个:
image.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void{fromThumbnail(e,i)});
传递i
。但是,当我单击任何图像时,函数缩略图会打印最后一个 i
。
这个问题有解决办法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果“i”是实例变量,则
fromThumbnail(e,i);
将始终传递实例变量的当前值;不考虑将事件侦听器添加到图像时的值是什么。如果您尝试引用添加了侦听器的图像,则可以在处理函数中使用
e.target
。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.