header
ask question
Click here to ask Question Now Its free No registration required. Flash, Flex, Flash Media Server, ActionScript,Adobe Air. Most questions receive a response in an hour.
subbu
Points:0
Posts:0

7/12/2010 5:27:43 AM

Title: Difference between target and currenttarget


Hi,

What is the Difference between target and currenttarget?

Regards,
Subbu



1
Shawn
Points: 270
Posts:0
7/12/2010 5:48:06 AM



event.target is the actual component which fires the event and stays same always , however the event.currentTarget changes as the event bubbles. For e.g you have a textfield in a hbox, on click the event.target will always be the textfield but in case of event.currentTarget the event will bubble and the current target will be textField then hbox and finally Application.

2
Tyler
Points: 230
Posts:0
7/12/2010 6:01:05 AM



subbu great question, difference vs target and currenttarget fascinates many people. It confuses many people. so have patience while reading.

target actually tells us where the object was clicked so stays always same. Using it can cause a problem because its does not always refer to the component but can also refer to some object inside the component.i.e on button click target can refer to some inside object of button also. Say we have a button with some more sub-components inside when clicking button if some inside component of button gets hit its target will be application.button.insideComponent but you expected it to be application.button. So its not a good practice to use it until you know that the component does not have a sub component.

Now comes the currentTarget. It should be always used as it will always point to the component to which the listener was attached. Events bubble which means when we click the event is received by inside component of button then button then application. So if you attached the event listener to button you will receive the event.currentTarget as application.button and if listener is on application the you will receive the currentTarget as application. So this is always the same component where the listener was attached. Use this always.

3
Justin
Points: 260
Posts:0
7/12/2010 12:37:03 PM



Great Tyler thanks :)


Post your Reply
Name  

Email

Type your Reply or Answer

Are you human? What is 2+5 



Members Login

Email  
Password
Forgot Password





This website focus on: Flash | Flex | FMS | RED5 | WOWZA | Flash Media Server | Adobe AIR | ActionScript,Flash Solutions | Flash Question | Flash Answers | Flash Developers | Flash Problem, Flash Help, Flash bugs, Flash workaround | Flash Blog | Flex Question Answers | Flash Forum | Flex Development | Actionscript development | Flash development | Adobe AIR development
Copyright © 2008 AskMeFlash.com. All rights reserved. Privacy Policy | Terms & Conditions