Flex中的target和currenttarget有什么区别?
谁能告诉我 Flex 中 target 和 currenttarget 之间的区别吗?
Can any one please tell me the difference between target and currenttarget in flex?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当然,我也遇到过一些麻烦。
currentTarget
属性是您为其注册事件处理程序的 IEventListener。目标
是调度您当前正在处理的事件的目标。因此,currentTarget
发生了变化,而target
却没有变化。查看以下示例:
示例应用程序
输出
这是一个简单的显示对象树,当应用程序准备就绪时,我:
Event.COMPLETE
。由于所有内容都已为同一事件注册了一个 eventHandler,并且由于我已将“bubbles”设置为 true(“new Event(type, bubbles)”),因此树中的任何内容(从子级)对于为
Event.COMPLETE
注册了事件处理程序的 grandGrandParent 及更高版本,将运行该方法:completeHandler
。事件沿着链条向上传播,然后返回。target
是调度该事件的目标,因此由于child
调度了它,因此它应该是常量。currentTarget
是发生变化的部分。这意味着,假设您想要检查何时滚动 Flex 中的 DataGrid,您想知道何时滚动 DataGrid 中的 itemRenderer 之一内的复选框。一种方法是在每个 itemRenderer 的
MouseEvent.ROLL_OVER
复选框上添加 EventListener。另一种方法是为MouseEvent.ROLL_OVER
添加事件监听器到 DataGrid 本身,并检查事件的目标:这就是我经常使用
event.target< /代码>。
希望有帮助,
槊
Sure, I've had some trouble with this too. The
currentTarget
property is the IEventListener you registered the event handler for. Thetarget
is the one that dispatched the event that you are currently handling. So thecurrentTarget
changes, thetarget
doesn't.Check out the following example:
Sample App
Output
It's a simple tree of display objects, and when the app is ready I:
Event.COMPLETE
.Since everything has registered an eventHandler for that same event, and since I have set
bubbles
to true (new Event(type, bubbles)
), anything in the tree, from child to greatGrandParent and beyond, that has registered an event handler forEvent.COMPLETE
, will run that method:completeHandler
. Events travel up the chain then back down. Thetarget
is the one that dispatched the event, so sincechild
dispatched it, it should be constant. ThecurrentTarget
is what changes.This means that, say you want to check when you are rolling over a DataGrid in Flex, you want to know when you roll over a Checkbox inside one of the itemRenderers in the DataGrid. One way is to addEventListener on every itemRenderer's checkbox for
MouseEvent.ROLL_OVER
. Another way is to addEventListener to the DataGrid itself forMouseEvent.ROLL_OVER
, and check what the target is on the event:That's how I often use
event.target
.Hope that helps,
Lance
因此可以提供帮助:
http://livedocs。 adobe.com/flex/3/html/help.html?content=events_08.html#219548
Thus could help :
http://livedocs.adobe.com/flex/3/html/help.html?content=events_08.html#219548
您应该阅读此网站上的教程:http://www.adobe.com/devnet/在提出这样的问题之前,请先了解 Flex/videotraining/ 对 Flex 的介绍。您的问题已在第一天得到解答。
You should go through tutorials on this site: http://www.adobe.com/devnet/flex/videotraining/ for an introduction to Flex before asking a question like this. Your question is covered on day 1.