Groups | Blog | Home
all groups > flash actionscript > november 2005 >

flash actionscript : Moving a MovieClip


Spot3313
11/10/2005 11:23:51 PM
Hey,

im trying to create a function that i can call on several buttons that will
move images when a btn is pressed... however im doing something wrong... i
think it might be the distX in my function but im not to sure

function moveImage(clipName, xDist) {
xDist = _x
speed = 25;
_x +=(clipName-_x)/speed;
}

push.onPress = function() {
moveImage(ball, 25);
}
Wolf van Ween
11/10/2005 11:36:36 PM
Why do you set xDist to _x?
Also whose _x do you want to change? I guess you want to change the ball's? Then you have to write clipName._x and so on.
Cheers
SBAR_weenie
11/10/2005 11:40:41 PM
Yes,

Something like:

function moveImage(xDist, clipNAme) {
clipName._x += xDist;
Spot3313
11/11/2005 12:00:09 AM
MmmMMm no... what im trying to do is when i press the button, i want the ball
to move as if it were being tweened... but what it does with this updated code,
is jump 25px... which makes sense, but its not what im going for....





function moveImage(xDist, clipName) {
clipName._x += xDist;
speed = 5;
_x +=(clipName-_x)/speed;
}

push.onPress = function() {
moveImage(25, ball);
}
SBAR_weenie
11/11/2005 1:06:46 AM
Right,

What you are trying to do is counter to the way flash likes to do things which
is to run when nothing is going on. What you need is to create a movieclip
inside the downstate of your button and send your function from the timeline
there.
Spot3313
11/11/2005 1:14:05 AM
its not a button, its a MC so i can script it in the main actions layer.

do you have flash 8 i dont mind posting what im doing?

otnateos
11/11/2005 1:15:38 AM
Spot3313
11/11/2005 1:24:24 AM
heres my fla, its flash 8... hope you guys can open

SBAR_weenie
11/11/2005 1:34:00 AM
Haven't looked at the file, but suggest you use the setInterval function.

onPress would set the interval, and onRelease would remove the interval. Read
the documentation carefully for setInterval in the HELP file, fun little device.
otnateos
11/11/2005 1:59:22 AM
Originally posted by: Spot3313
heres my fla, its flash 8... hope you guys can open

www.teksunstudios.com/_misc_picture/move_ball.zip

NSurveyor
11/11/2005 3:16:50 AM
I would say onEnterFrame would be the simplest solution:

function moveImage(xDist, clipName, speed) {
clipName.onEnterFrame = function(){
this._x +=(xDist-this._x)/speed;
if(Math.abs(xDist-this._x)<1){
delete this.onEnterFrame;
}
}
}

push.onPress = function() {
moveImage(25, ball, 5);
}
AddThis Social Bookmark Button