# onEnterFrame problems

**URL:** <https://forum.kirupa.com/t/onenterframe-problems/244745>\
**Category:** Uncategorized\
**Created:** [November 21, 2007, 11:34am UTC](https://forum.kirupa.com/t/onenterframe-problems/244745 "2007-11-21T11:34:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ubermeowmix](https://avatars.discourse-cdn.com/v4/letter/u/7cd45c/32.png) [@Ubermeowmix](https://forum.kirupa.com/u/Ubermeowmix)\
**Post date:** [November 21, 2007, 11:34am UTC](https://forum.kirupa.com/t/onenterframe-problems/244745/1 "2007-11-21T11:34:40Z")

</div>

I’m using onEnterFrame to initialize a function, but it’s adding all the other elements on the page and giving them the code as well. Why is it doing this and how do I make the object initialize the function locally (if thats the correct terminology).

CODE:

ball.onEnterFrame = function() {  
vel.y+=gravity;  
vel.x+=wind;  
pos.x+=vel.x;  
pos.y+=vel.y;  
\_x=pos.x;  
\_y=pos.y;  
//  
if (pos.y+radius \> movie.height){  
pos.y = movie.height-radius;  
vel.y\*=-\_root.restitution;  
}  
if (pos.x+radius \> movie.width){  
pos.x = movie.width-radius;  
vel.x\*=-\_root.restitution;  
}  
if (pos.x+radius \< movie.\_x){  
pos.x = movie.\_x-radius;  
vel.x\*=+\_root.restitution;  
}  
//counter and wind change animation movement  
counter–;  
if (counter\<0){  
var newTime:Number=Math.random(30);  
var newMinusTime:Number=Math.random(10);  
counter=+newTime;  
if (newMinusTime\<3){  
wind=-wind+newTime;  
}  
windChange();  
}  
}

It’s just a jaunt into gravity, nothing special! But I’m clearly doing something drastically wrong.
