Why use "this."?

Why do you have to use “this”? If you leave it out, the script still works the same way.

Good coding practice.

And when doing object oriented programing the difference of this and no this is sometimes integral. This being a good example of why…

http://www.kirupa.com/developer/actionscript/tricks/scope.asp

this.myMovie.gotoAndPlay(1); is the same thing as myMovie.gotoAndPlay(1);. Right?

Yes, they are the same.

*Originally posted by Supree *
**this.myMovie.gotoAndPlay(1); is the same thing as myMovie.gotoAndPlay(1);. Right? **
not all the time! You could have a myMovie inside another movieclip which this was called and you’d have to use this.myMovie…

You could also have a myMovie on the root in which case, myMovie…would refer to it.

basically the difference lies in function calls

In coding normally directly within the scope of a timeline and not withn any function, this can be pretty much always left out. There are minor differences of using this and not using this but nothing to really worry about.

otherwise, its the function calls where this comes into play. In a function, ‘this’ refers to the object or timeline which the function exists. If you dont use this, then whatever variable you’re trying to get is checked in the timeline the function was written - and the timeline it was written is not always the timeline it exists. ex:

num = 5;
createEmptyMovieClip("myMC",1);
myMC.num = 10;
myMC.testFunc = function(){
	trace(num); // traces 5
	trace(this.num); // traces 10
}
myMC.testFunc();

you can see here two num variables. One in the timeline this code is being written, and one in the movieclip created within that timeline. That movieclip is then given a function. This function, though its assigned to exist in myMC, is, as you can see, being written in that current timeline. So, when the function is run, num is 5 - the value of num in the timeline the function was defined and this.num is 10 - the value of num in the object the function itself exists which is myMC.