Can any one please tell me the difference between target and currenttarget in flex?
Can any one please tell me the difference between target and currenttarget in flex?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Sure, I’ve had some trouble with this too. The
currentTargetproperty is the IEventListener you registered the event handler for. Thetargetis the one that dispatched the event that you are currently handling. So thecurrentTargetchanges, thetargetdoesn’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
bubblesto 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. Thetargetis the one that dispatched the event, so sincechilddispatched it, it should be constant. ThecurrentTargetis 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