Movement

hi everyone

i need help on this
i saw this tutorial about movement with actionscript here on kirupa

http://www.kirupa.com/developer/mx/ASmovement.htm

its great,its working but what i want to know is how can we make the movement stop on determined _x position,i’ve tryed to put an if statement to stop when it reaches some _x position ,it worked but it didn’t work smoothly it gets the movieclip to _x position without the smoothness and i’de like to keep the smooth movement
can someone help me please?
thanks

are you sure you coded right ?
try this, change the x variable:


onClipEvent(enterFrame) {
	speed = 1;
	this._x += speed;
        if (this._x >= 100){
             this.stop();
             _root.stop // i'm not sure this is useful
            }
}

hi mlkdesign

thanks for the help

i’ve tried to use it as you said but it doesn’t work ,when the movieclip reachs the _x=100 it continues to move i don’t know why somehow it seems that it doesn’t “see” the If condition

MLK - love the footer - gotta click it everytime I see it!!

What I do when I want an AS movement to stop is either tell speed to equal 0. This is what I mean:
[AS]
onClipEvent(enterFrame) {
speed = 1;
this._x += speed;
if (this._x >= 100){
speed=0;
}
}
[/AS]
Can’t move without the pedal down. Hope that helps!!
(-:

if you want to stop the MC smoothly, you may want to use easing. an example:

[AS]
myMC.newx = 400
myMC.speed = 8
myMC.onEnterFrame = function () {
this._x = this._x-(this._x - newx)/this.speed
}[/AS]
newx is where you want the MC to stop and speed is how fast you want it to get there. i didn’t check out which tutorial you read so i may be wrong :*(

hope i helped :slight_smile:

ok guys
thanks for all the help but i have figure out myself a solution for this here it is

onClipEvent(EnterFrame){
count=this._x;
if (count==100){
this.stop();
}
else{
speed = 1;
this._x += speed;
count=this._x;
}
}
the only thing is to put the condition right which means we have to see first if the movieclip has already reached the position we want and if its true we stop else we continue to move

*Originally posted by zylum *
**if you want to stop the MC smoothly, you may want to use easing. an example:

[AS]
myMC.newx = 400
myMC.speed = 8
myMC.onEnterFrame = function () {
this._x = this._x-(this._x - newx)/this.speed
}[/AS]
newx is where you want the MC to stop and speed is how fast you want it to get there. i didn’t check out which tutorial you read so i may be wrong :*(

hope i helped :slight_smile: **

this should be…

[AS]myMC.newx = 400
myMC.speed = 8
myMC.onEnterFrame = function () {
this._x +=(this.newx-this._x )/this.speed
}[/AS]

cheers =)!

why to submit pintless var “newx”?

*Originally posted by fluid_0ne *
**why to submit pintless var “newx”? **

Because if you want to change the location the clip goes to you can just change the value of the newx variable.

but there’s no need for doing that in this eg.

You never know…