[FMX] functions

On the first frame (and currently the only frame) of my main timeline I have the following code
[AS]
_root.plane.onEnterFrame = function() {
_y += gravity;
if (Key.isDown(Key.LEFT)) {
_x -= 1;
_rotation = -5;
} else {
_rotation = 0;
}
if (Key.isDown(Key.RIGHT)) {
_x += 5;
_rotation = 3;
} else {
_x += 2;
}
};
[/AS]

This works fine until I place more stuff on the stage and everything starts to follow the function. I have tried it with and without the _root. Now if I put a [AS]this[/AS] before each property it works fine. why is that? if this code is being place on the plane?

I am still new to writting my code this way - any help in undesrstanding would be appreciated.

THANKS,
Tobias

By calling _root.plane.onEnterFrame you are assign all actions in that function to the movie clip with the instance name “plane” (no quotes) on the _root timeline. So you would need to use “this” instead of _root.

If you want to use the same actions on multiple clips then you will have to define the actions in a function or a prototype that can be called by each individual clip. If you want to do that, check out these tutorials…

About Prototypes:
http://www.kirupa.com/developer/actionscript/tricks/prototypes.asp

Handling Variables across functions/prototypes:
http://www.kirupa.com/developer/actionscript/spring2.htm

Yep, basically, properties (and more generally variables), when put just like that in functions, refer to the current timeline. In your case _root. Putting this. in front of the properties make them relative to object calling the function, in your case plane.