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); }
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
Yes, Something like: function moveImage(xDist, clipNAme) { clipName._x += xDist;
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); }
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.
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?
heres my fla, its flash 8... hope you guys can open
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.
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); }
Don't see what you're looking for? Try a search.
|