# Stop the loop function

**URL:** <https://forum.kirupa.com/t/stop-the-loop-function/322734>\
**Category:** Uncategorized\
**Created:** [June 1, 2011, 6:50am UTC](https://forum.kirupa.com/t/stop-the-loop-function/322734 "2011-06-01T06:50:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gopik3](https://avatars.discourse-cdn.com/v4/letter/g/4af34b/32.png) [@gopik3](https://forum.kirupa.com/u/gopik3)\
**Post date:** [June 1, 2011, 6:50am UTC](https://forum.kirupa.com/t/stop-the-loop-function/322734/1 "2011-06-01T06:50:10Z")

</div>

Am Creating a game in as2 an object come from left to right Randomly how do i stop the object i written script in single frame but it runs in all frame of the game  
\_root.onEnterFrame = function() {  
passed++;  
if (passed\>speed) {  
passed = -1;  
collect = _root.attachMovie(“pea”, "pea_"+placed, \_root.getNextHighestDepth(), {\_y:Math.random((0.001))_250});  
collect.gotoAndStop(Math.floor(Math.random()collect.\_totalframes)+1);  
collect.angle = Math.abs(0);  
collect.xspeed = velocityMath.cos(0);  
collect.yspeed = velocity_Math.sin(0);  
collect.onEnterFrame = function() {  
this.\_x += this.xspeed;  
this.\_y += this.yspeed;  
x\_dist = this.\_x-player1.\_x;  
y\_dist = this.\_y-player1.\_y;  
if (this.\_x\<0) {  
this.\_x = 0;  
this.xspeed \*= -1;  
}
