The 'this' keyword is used to refer to an instance of a class
from within that class. Let's say you have a simple class
MySimpleClass (refer to the code below):
Quite often you may name a parameter, like 'orderNum' in the
constructor of the class:
public function MySimpleClass(
orderNum:String)
The name of this parameter could be the same as a private or
protected variable (property) that is defined within this class. So
in our example, this class variable is also named 'orderNum':
private var
orderNum:String
Well, how do you differentiate between the two then? You use
the 'this' keyword, so that 'this.orderNum' refers to the class
variable defined by private var orderNum:String and you assign the
value associated with the 'orderNum' parameter in the class
constructor to that class variable.
If you instantiate your class, you'll do something like:
var mySimpleClass:MySimpleClass = new
MySimpleClass("A324B6768");
That's one example where you would use the 'this' keyword.
'target' and 'currentTarget' are used like this:
When you register an event listener using addEventListener
with a component or the stage, that component or the stage becomes
the currentTarget in the listener function:
stage.addEventListener(MouseEvent.CLICK, onClick); //the
stage will be the currentTarget
Try this:
Drag a button onto the stage. Give it an instance name of
'myButton' or something. Then add the example target/currentTarget
code below to the main timeline frame script that the button was
placed on. Publish the movie and you'll see the following:
When you click on the stage only -
» trace output for event.currentTarget will be the stage
» trace output for event.target will be nothing
When you click on the button only -
» trace output for event.currentTarget will be the stage
» trace output for event.target will be myButton
You didn't have to add the event listener to the button, and
yet it still can be referred to in the event handler (via
event.target) that is associated with the stage. This is due to the
way certain events are propagated through the event chain in AS3.
Hope this helps.
TS