Copy link to clipboard
Copied
OK, at first this seemed like the easiest thing to do, but I've tried to make it work a number of different ways and nothing seems to work. I have a movie clip that I want to have constantly moving back and forth across the stage, basically "bounce" off the left and right sides. What's the best way to do this using AS2?
if you want your object with left-edge reg point to move right initially:
yourobject.speed=3;
yourobject.onEnterFrame=function(){
if(!this.moveleft){
this._x+=this.speed;
if(this._x>=Stage.width-this._width){
this.moveleft=true;
}
} else {
this._x-=this.speed;
if(this._x<=0){
this.moveleft=false;
}
}
}
Copy link to clipboard
Copied
if you want your object with left-edge reg point to move right initially:
yourobject.speed=3;
yourobject.onEnterFrame=function(){
if(!this.moveleft){
this._x+=this.speed;
if(this._x>=Stage.width-this._width){
this.moveleft=true;
}
} else {
this._x-=this.speed;
if(this._x<=0){
this.moveleft=false;
}
}
}
Copy link to clipboard
Copied
This works perfectly, thank you. However, it seems to have messed up another movie clip. I have a second movie clip that uses a motion tewwn to get bigger and bigger until it reaches a certain size. When the main movie clip isn't moving the motion tween works perfectly, but if the main movie clip is moving the motion tween suddenly stops working. Is there a way to fix this?
Copy link to clipboard
Copied
is your other tween using an onEnterFrame method applied to the same movieclip?
Copy link to clipboard
Copied
Nope, no AS, just a regular tween added between two keyframes. The tween is on the timeline of the movieclip, not on the main timeline. So, when the movie clip loads it automatically runs through it's own timeline. It gets bigger and bigger, then at the end of it's timeline the movieclip gets removed. The timeline seems to play properly because after a couple second the movie clip does get removed, it just doesn't get bigger. Why would having one movie clim move back and forth stop another movie clip from using it's tween?
Copy link to clipboard
Copied
it wouldn't unless there's some relationship between the two movieclips.
Copy link to clipboard
Copied
I think I may have figured it out. I added your code to the first frame of the movie clip I wanted to move, rather than the main timeline. I put in this.speed and this.onEnterFrame instead of using the movie clip's instance name. I changed it to _root.movieclip.speed and _root.movieclip .onEnterFrame and it seems to be working properly now. Strange how using this. instead of the instance name made the tween stop working.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more