Possible Duplicate:
What is the difference between target and currenttarget in flex?
What is the difference between Target and Current Target in Flex especially in mouse events. An example would be advantageous.
Possible Duplicate:
What is the difference between target and currenttarget in flex?
What is the difference between Target and Current Target in Flex especially in mouse events. An example would be advantageous.
When you handle the event from a parent container, and not from the actual dispatching object you want to be able to make the difference between
the target object – the one that actually dispatched the event in the first place the container that handles that event The event object has two properties that can be used to determine the target object and the current target – the container that currently handles the event. These are target and currentTarget
In the previous post I talked about the event propagation phases in Flex and I said that events in Flex can be handled both on the target object – the dispatching object – or on any of it’s parent containers.
I will use the same example from the previous article with minor changes to the event handler function:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
click="buttonClicked(event)"
viewSourceURL="srcview/index.html">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
private function buttonClicked(event:MouseEvent):void{
Alert.show('target object: ' + event.target.name
+ '\n' +
'current target object: ' + event.currentTarget.name);
}
]]>
</fx:Script>
<s:layout>
<s:VerticalLayout horizontalAlign="center"/>
</s:layout>
<s:VGroup click="buttonClicked(event)">
<s:Button label="Click Me!"
click="buttonClicked(event)" />
</s:VGroup>
</s:Application>