View Full Version : Moving objects
I was wondering if there is syntax in Actionscript where you can smoothly move an object from point "A" to point "B", just like a tween... Here is some fictitious code to help explain my question:
tweenTo (Initial X, Initial Y, Destination X, Destination Y)
That code obviously won't work, so I am looking for the correct syntax. If you can help me that would be great. Thanks alot!
-Layz
jessup
03-16-2005, 01:40 AM
flash mx04 uses a tween class inwhich u can find a tut for it in the tut section on this site under advanced.
any other way u can use a onEnterFrame call to make it move the object.
so to answer your question yes it is very possible and actually quite easy
burnedalive
03-16-2005, 01:44 AM
This is a simple example moving a movie clip called 'square' across the screen a little ways.
var xdestination = 100;
square.onEnterFrame = function()
{
if(_x < xdestination){
_x +=1;
}
}
Every frame, x is incremented by 1px, so if you have 30 fps, x should move to the right 30px every second, until it has moved to x = 100 (not necessarily moved 100px).
This is a simple example moving a movie clip called 'square' across the screen a little ways.
var xdestination = 100;
square.onEnterFrame = function()
{
if(_x < xdestination){
_x +=1;
}
}
Every frame, x is incremented by 1px, so if you have 30 fps, x should move to the right 30px every second, until it has moved to x = 100 (not necessarily moved 100px).
That sort of works. Here is the code I have made:
onClipEvent (enterFrame) {
randomx = Math.floor(Math.random() * (100 + 1)) - 1;
if (_x < randomx) {
_x += 1;
} else {
_x -= 1;
}
}
As you can see I want the target's X position to "tween" from the current position (_x), to a random position (randomx). But all the above code is doing is moving the target back and forth 1 pixel each time, and it's not going further than about 5 pixels from it's initial position. Thanks for the help thus far! :D
nthpixel
03-18-2005, 12:37 AM
That's because randomx is being revalued at every frame. You need to specify randomx outside of onClipEvent(enterFrame)
vBulletin® v3.7.1, Copyright ©2000-2009, Jelsoft Enterprises Ltd.