# Flash MX animation actionscript problem

**URL:** <https://forum.kirupa.com/t/flash-mx-animation-actionscript-problem/15329>\
**Category:** flash\
**Created:** [March 13, 2003, 2:57am UTC](https://forum.kirupa.com/t/flash-mx-animation-actionscript-problem/15329 "2003-03-13T02:57:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![CopperGoat](https://avatars.discourse-cdn.com/v4/letter/c/c6cbf5/32.png) [@CopperGoat](https://forum.kirupa.com/u/CopperGoat)\
**Post date:** [March 13, 2003, 2:57am UTC](https://forum.kirupa.com/t/flash-mx-animation-actionscript-problem/15329/1 "2003-03-13T02:57:04Z")

</div>

Hey everyone, I have started moving an object with the following actionscript code found in the tutorials site at kirupa…

onClipEvent(enterFrame)  
{  
speed = -2;  
this.\_y += speed;  
}

This will make the object move directly upwards. This is what I want. I want the object to constantly move upwards until the y-coordinate is 75. when it reaches 75, it would stop moving upwards. This is what I tried but it does not work…

onClipEvent(enterFrame)  
{  
speed = -2;  
this.\_y += speed;  
if (this.\_y == 75)  
{  
break;  
}

}

Does anyone know what is wrong? Thanks.

---

<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:** [March 13, 2003, 3:52am UTC](https://forum.kirupa.com/t/flash-mx-animation-actionscript-problem/15329/2 "2003-03-13T03:52:51Z")

</div>

Come on, I need help. Please? 🙂

---

<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:** [March 13, 2003, 4:03am UTC](https://forum.kirupa.com/t/flash-mx-animation-actionscript-problem/15329/3 "2003-03-13T04:03:07Z")

</div>

problem 1) 2 can not be divided into 75 evenly, so == will never be true, so that will never be called on. You need to do \<= 75 or \>= 75 (depending on your direction).

problem 2) break is used for loop functions like for, while, etc loops and it will not stop your movie clip.

Solution  
[AS]onClipEvent (enterFrame) {  
speed = -2;  
this.\_y += speed;  
if (this.\_y\<=75) {  
this.\_y = 75;  
}  
}[/AS]

But see, this will keep running the enterFrame, but leave the clip in the same spot. That is quite inefficient. So we can set up a prototype with the new dynamic event handlers in Flash MX.

[http://www.kirupa.com/developer/actionscript/tricks/prototypes.asp](http://www.kirupa.com/developer/actionscript/tricks/prototypes.asp) \<-- read up on prototypes.

[http://www.kirupa.com/developer/actionscript/tricks/dynamicevent.asp](http://www.kirupa.com/developer/actionscript/tricks/dynamicevent.asp) \<-- read up on dynamic event handlers.

Ok, lets continue.

We create our function and throw it on a frames actions.  
[AS]speed = -2;  
//create prototype function called moveMe  
MovieClip.prototype.moveMe = function() {  
//create onEnterFrame dynamic event handler  
this.onEnterFrame = function() {  
//move along y axis  
this.\_y += speed;  
//if the \_y position is less than 75  
if (this.\_y\<=75) {  
//the \_y position stays at 70  
this.\_y = 75;  
//delete the onEnterFrame so it will stop running  
delete this.onEnterFrame;  
}  
};  
};  
//call the prototype to the movieClip with the instance name of “myClip”  
myClip.moveMe();[/AS]

---

<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:** [March 13, 2003, 1:17pm UTC](https://forum.kirupa.com/t/flash-mx-animation-actionscript-problem/15329/4 "2003-03-13T13:17:23Z")

</div>

Thanks lost in beta! Your solution worked. i thought the enterframe was sort of a loop, because it repeats itself. That’s why i used the break function. But thanks for clearing that out for me.

---

<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:** [March 13, 2003, 5:29pm UTC](https://forum.kirupa.com/t/flash-mx-animation-actionscript-problem/15329/5 "2003-03-13T17:29:15Z")

</div>

enterFrame is a handler. It tells the code to activate everytime the frame the clip is in is entered. If it is stopped on that frame, then it keeps “looping” around telling it to keep activating the code, but thats about it.

I am glad my solution worked.
