As has already been mentioned, you don't need to use this in a very simple case, where you want to refer to a class member variable from a class member method, e.g.:
public function myClassMethod() : void
{
// "this" is redundant here, as it is implied if omitted
this.myPrivateOrPublicVariable = 123;
}
Do note though that there are cases where this (which is evaluated at the time it is encountered in a program, rather than at instantiation as one might guess) does not refer to the class in which it is written. More specifically, this happens when you use it inside a function that will get called using a method such as Function.apply(). This method allows the caller to specify the object that will be referred to by this, and it is commonly used in callbacks, e.g. in tweening engines.
// Call myFunction(listOfArguments[0], listOfArguments[1] ...),
// with this referring to objectReferredToByThis.
myFunction.apply(objectReferredToByThis, listOfArguments);
Here's an example with the popular tweening engine Tweener, where the default behavior is to have this refer to the tweened object (i.e. the MovieClip _mc), rather than to an instance of the class in which this is written (i.e. MyClass).
package
{
/* ... imports ... */
public class MyClass extends Sprite
{
private var _mc : MovieClip;
public function tweenSomething() : void
{
var tween : Object = {
x: 0,
time: 1,
onComplete: function() : void {
// Here, "this" will not refer to the instance
// of MyClass, but rather to the _mc MovieClip,
// which is the object being tweened below.
this.visible = false;
}
};
Tweener.addTween(_mc, tween);
}
}
}
In the above code, the use of this is necessary, because we want to explicitly instruct the runtime to modify the visible state of our MovieClip (_mc). Had we not used this, the visible reference would have referred to MyClass.visible, because of function closure.