Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In the following code we use target in the function:

moon.mouseEnabled = false;

addEventListener(MouseEvent.MOUSE_DOWN, onDrag, false, 0, true);
addEventListener(MouseEvent.MOUSE_UP, onDrop, false, 0, true);

function onDrag(evt:MouseEvent):void {;;

function onDrop(evt:MouseEvent):void {

But if I rewrite this code without it still work. So what is the difference, am I going to get errors later in the run time because I didn't put target? If not then why some use target a lot while it works without it.

function onDrag(evt:MouseEvent):void {
share|improve this question
" I going to get errors later in the run time..." You mean you didn't run it to see if it was the same? Just because two different methods both compile does not mean they are equivalent, just syntactically correct. – Byte56 Aug 26 '12 at 16:43

The target property of an Event is the object that triggered the event! So if you mouse-down on a sprite on your stage, the "moon" object will get attached to the clicked sprite (because events bubble)!

So no, these examples don't do the same thing!

If you did this, then it would be the same thing:


That is because currentTarget is always the object that had the event listener attached to. Generally, you should learn about scope. If your event handler function is on another object than the event listener was attached to, the two methods wouldn't do the same thing either.


// this adds "moon" to the object that triggered the event;

// this adds "moon" to the object that had the event-listener added to it

// this adds "moon" to "this" (current scope)

Sometimes these might be the same, unde other conditions they won't be the same.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.