Limit movieclip movement within a given boundary

97 views Asked by At

I am using an ActionScript 2.0 for my project. I have a movie clip that is moving along the x-axis. My problem is, I don't know how i can limit the movie clip on the given boundary because it moves continuously.

Here's my code:

onClipEvent (enterFrame) {
    speed = 1;
    this._x -= speed;
}
1

There are 1 answers

0
helloflash On
onClipEvent (load) {
    speed = 1;
    boundary = 100; 
}

onClipEvent (enterFrame) {
    if (this._x > boundary) {
        this._x -= speed;
    } else {
        this._x = boundary;
        delete this.onEnterFrame;
    }
}

Remark : you should write your code directly on the timeline:

var speed:Number = 1;
var boundary:Number = 100;

this.onEnterFrame = function():Void {
    if (clip._x > boundary) {
        clip._x -= speed;
    } else {
        clip._x = boundary;
        delete this.onEnterFrame;
    }
}