任何人都可以告诉我flex和targettarget之间的区别吗?flex中的target和currenttarget有什么区别?
9
A
回答
18
当然,我也遇到了一些麻烦。 currentTarget
属性是您为其注册事件处理程序的IEventListener。 target
是分派您正在处理的事件的人。所以currentTarget
更改,target
不。
看看下面的例子:
示例应用程序
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="addListeners()">
<mx:Script>
<![CDATA[
protected function addListeners():void
{
greatGrandParent.addEventListener(Event.COMPLETE, completeHandler);
grandParent.addEventListener(Event.COMPLETE, completeHandler);
aParent.addEventListener(Event.COMPLETE, completeHandler);
child.addEventListener(Event.COMPLETE, completeHandler);
// dispatch event that "bubbles", second param is "true"
// dispatched from child
child.dispatchEvent(new Event(Event.COMPLETE, true));
}
protected function completeHandler(event:Event):void
{
trace("target: ", event.target + ", currentTarget: ", event.currentTarget);
}
]]>
</mx:Script>
<mx:Panel id="greatGrandParent">
<mx:Panel id="grandParent">
<mx:Panel id="aParent">
<mx:Button id="child"/>
</mx:Panel>
</mx:Panel>
</mx:Panel>
</mx:Application>
输出
target: MyApp.greatGrandParent.grandParent.aParent.child, currentTarget: MyApp.greatGrandParent.grandParent.aParent.child
target: MyApp.greatGrandParent.grandParent.aParent.child, currentTarget: MyApp.greatGrandParent.grandParent.aParent
target: MyApp.greatGrandParent.grandParent.aParent.child, currentTarget: MyApp.greatGrandParent.grandParent
target: MyApp.greatGrandParent.grandParent.aParent.child, currentTarget: MyApp.greatGrandParent
这是显示目标的简单树,当应用程序已经准备好我:
- 为树中每个组件上的相同事件添加侦听器。
- 发送任意事件(仅供演示)。我选择了
Event.COMPLETE
。
既然一切都已经注册的事件处理程序对于同一事件,因为我已经设置bubbles
为true(new Event(type, bubbles)
),什么树,从小孩到greatGrandParent和超越,已注册的事件处理程序Event.COMPLETE
,将运行该方法:completeHandler
。事件沿着链条传播,然后回落。 target
是派遣该事件的人,因此child
派遣它,它应该是不变的。 currentTarget
是什么改变。
这意味着,假设您想要检查何时在Flex中的DataGrid上滚动,您想知道何时滚动DataGrid中的某个itemRenderer内的复选框。一种方法是在每个itemRenderer的复选框上为MouseEvent.ROLL_OVER
添加EventListener。另一种方法是在对addEventListener到DataGrid本身MouseEvent.ROLL_OVER
,检查一下目标是对事件:
protected function dataGrid_rollOverHandler(event:MouseEvent):void
{
// event.currentTarget is DataGrid
if (event.target is CheckBox)
trace("rolled over checkbox!");
}
那怎么我经常使用event.target
。
希望帮助, 兰斯
1
-9
你应该去通过教程在这个网站:http://www.adobe.com/devnet/flex/videotraining/的介绍,问这样的问题之前弯曲。您的问题在第1天涵盖。
相关问题
- 1. target =“_ blank”和“target = blank”之间有什么区别?
- 2. Omniture Test&Target中的课程和ID有什么区别?
- 3. flex mxml和actionscript-3有什么区别?
- 4. Flex mx:DateField disabledRanges =“”和selectableRange =“”有什么区别?
- 5. Flex和Flash CS4有什么区别?
- 6. Shockwave,Flash和Flex有什么区别?
- 7. 有什么区别`和$(Bash中有什么区别?
- 8. Flex中的PopUpButton,PopUpMenuButton和ComboBox控件有什么区别?
- 9. 在Flex中,skin和itemRenderer有什么区别?
- 10. 在Flex中,'creationComplete'和'addedToStage'有什么区别?
- 11. ==和===有什么区别?
- 12. ==和===有什么区别?
- 13. 有什么区别? :和||
- 14. ==和===有什么区别?
- 15. '=='和'==='有什么区别?
- 16. `&`和`ref`有什么区别?
- 17. 有什么区别:。!和:r!?
- 18. | 0和~~有什么区别?
- 19. Appender和〜有什么区别?
- 20. python中的{}和[]有什么区别?
- 21. 列表中的:::和++有什么区别?
- 22. SQL中的“LIKE”和“=”有什么区别?
- 23. console.log中的和+有什么区别?
- 24. Perl中的'eq'和'=〜'有什么区别?
- 25. Prolog中的'和“有什么区别?
- 26. MATLAB中的{}和[]有什么区别?
- 27. PHP中的 - >和::有什么区别?
- 28. .container .flexbox和.flex-container之间有什么区别
- 29. xtype和别名有什么区别?
- 30. XSD中IDREF和IDREFS有什么区别?