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…
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.
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.
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]
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.
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.