Question : Flash movement action script!

I use flash to build a small boat slowly sliding on water (left to right or r to l). I want to use script to control movement instead of each frame.  Could you help me to figure out how I can use script to control this horizontal slowly moving from left to right?


Thanks!

Rose

Answer : Flash movement action script!

well, did u loop the frame ... so it adds mc._x+=1; untill it gets to 500?? ...

hmmm ... in ur original movie, ur boats movement were created by tween, if u wanna slow them down, change the frame rate or make the animation longer, so it takes more frame to move from A to B ...

otherwise u can create a movieclip and write scripts to made it move, ... it is a bit more complicated, but ...

create a movieclip with the boat image
in the movieclip, set the speed and direction individually

//frame 1
speed = 1; //left to right
stageWidth = 500;

//frame 2
_x += speed;
if ( ((_x + _width) > stageWidth ) && (speed > 0)){ // if the stage is 500 wide
   _x = -(_width); // bring the boat back to the left
} else if (((_x - _width) < 0 ) && (speed < 0)) {
   _x = stageWidth + _width; // bring it to the right
}

//frame 3
gotoAndPlay(2);


the above script will move the boat move change the variables in frame for the speed (pixel/frame) and width of the stage (use Stage object to check the stage width in MX)

or ....
a more complicated way to do it ...
write script to move the boat, modify it so u can pass the speed parameter to it use a function to add the boat dynamically use attchMovie() ...
 
see the fla for explanation
http://www.smartclever.net/example/flash/boat/4boat.swf
(2 repeat & 2 once only)
http://www.smartclever.net/example/flash/boat/rboat.swf
(random boat every 2 sec)
http://www.smartclever.net/example/flash/boat/boat.fla
(source)

have fun :)
Random Solutions  
 
programming4us programming4us