Skip to main content
Inspiring
August 29, 2011
Answered

this vs e.currentTarget ?

  • August 29, 2011
  • 1 reply
  • 1502 views

I have several movie clips on the stage. They are draggable. I want to be able to drag the movie clip, then when it is dropped, a copy of that movie clip will appear where the first one had been, and the first one will just stay where it is on the screen.

However, I'm running into problems with the syntax. I don't have a good  grasp on the difference between "this" and "e.currentTarget".

Here is my current code:

public function letterStop(e:MouseEvent): void {
            if (this.dropTarget.parent is BlankSquare) { //check to see if the movie clip is being dropped over a drop spot
                e.currentTarget.x = this.dropTarget.parent.x + 10; //lock movie clip to the drop spot
                e.currentTarget.y = this.dropTarget.parent.y - 10;
                var newLetter:Letters = new Letters(); //create a new instance of the class Letters
                newLetter = e.currentTarget; //assign the new instance to the properties of the current instance
                MovieClip(this.parent).bmc.addChild(newLetter); //add child to the stage
                newLetter.x = e.currentTarget.startPoint.x; //at the correct starting points
                newLetter.y = e.currentTarget.startPoint.x;
            }

}

This code obviously doesn't even compile, I'm missing something somewhere. I want the new movie clip to be a direct copy of the old movie clip. Each movie clip has a property called startPoint which holds its point of origin so it can snap back into place. I don't know how to spawn a copy of the original movie clip in the right place (since duplicateMovieClip no longer exists). And I'm really not sure if I'm using this or e.current Target correctly since they both trace to the same thing.

Does any of that make sense?

This topic has been closed for replies.
Correct answer relaxatraja

Okay, but what if I need that instance name to be a variable?

I'll be more specific.

I have 26 letters on the stage, A-Z. Each is a class (letterA, letterB, etc) whose base class is Letters.

If I drag the letter A onto a drop point, I need to duplicate that letter in the original movie clip's position so that it can be used again.

So I can't just say "create this new movie clip" because I can't figure out how to tell it WHICH movie clip it needs to duplicate. Does that make sense? Is it duplicating an M or a K? I don't know how to get it to do that.


I have attached a file for download a sample which you looking for:

http://www.mediafire.com/?68j644m983qrkn4

1 reply

relaxatraja
Inspiring
August 30, 2011

The below link will show you the clear difference between target and currentTarget:

http://www.wastedpotential.com/?p=10

AmbariAuthor
Inspiring
August 30, 2011

That's very informative, thanks!!

I read the whole thing and...I still can't figure out how it applies. :/

Colin Holgate
Inspiring
August 30, 2011

The article explained target and currentTarget, but it didn't talk about "this". "this" refers to the object that the script belongs to, so if it's the document class, "this" is probably the stage. If the class is for a movieclip, then "this" would be that movieclip.

So, "this" need not be target, currentTarget, or either of their parents.