# \[FMX\] functions

**URL:** <https://forum.kirupa.com/t/fmx-functions/19587>\
**Category:** flash\
**Created:** [April 29, 2003, 5:18pm UTC](https://forum.kirupa.com/t/fmx-functions/19587 "2003-04-29T17:18:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tgelston](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/tgelston/32/54_2.png) [@tgelston](https://forum.kirupa.com/u/tgelston)\
**Post date:** [April 29, 2003, 5:18pm UTC](https://forum.kirupa.com/t/fmx-functions/19587/1 "2003-04-29T17:18:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 29, 2003, 5:43pm UTC](https://forum.kirupa.com/t/fmx-functions/19587/2 "2003-04-29T17:43:02Z")

</div>

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](http://www.kirupa.com/developer/actionscript/tricks/prototypes.asp)

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 30, 2003, 11:48am UTC](https://forum.kirupa.com/t/fmx-functions/19587/3 "2003-04-30T11:48:19Z")

</div>

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.
