Random
Movement in Flash MX
         code by suprabeener :: tutorial by kirupa chinnathambi

A common observation users made on this site when migrating from Flash 5 to Flash MX is that some of the animations that worked in Flash 5 no longer work in Flash MX. One such animation was the popular Random Motion tutorial. Of course, an answer was right around the corner (on the forums!) Just as with the Flash 5 Random Movement code, suprabeener was more than kind enough to share his expertise in making the code work in Flash MX. So, thank you supra!

The following animation is a result of suprabeener's code and my infatuation with the post icons found on kirupaforum.com.

[ randomly moving cones! ]

You will create something similar to the above animation in about 5 minutes by following the instructions in this tutorial.

Creating Random Motion in Flash MX:

  1. Create a new movie in Flash MX. Set the width and height to anything you want.
     
  2. Now, draw something and make it a movie clip. To convert something into a movie clip, select it and press F8. From the Convert to Symbol Dialog box that appears, select the Movie Clip option and press OK:

[ the convert to symbol dialog box ]

  1. Once you have created your movie clip, here comes the complicated process of Copying and Pasting. Right click on Frame 1 (can be a keyframe or a blank keyframe) of your movie and select Actions.

    Copy and paste the following code into your Actions dialog box:

[ copy and paste the following code as an action on Frame 1 ]

  1. After the rigorous process of Copying and Pasting you undertook in Step 3, right click on your movie clip and select Actions. From the Actions dialog box that appears, copy and paste the following code:

[ add the above lines of code on your movie clip ]

  1. Now, copy and paste your movie clip as many times as you want on your timeline to create multiple, randomly-moving objects. You may even create a separate movie clip with a different object in it. Just make sure the above 3 lines of code are added to each movie clip that you want to move randomly:

[ multiple copies of cone movie clip with the three lines of code ]
 

 setting width and height of movement
The above code I pasted works for a finite browser size: 300 pixels by 200 pixels. More than likely, your may be larger or smaller than 300 by 200. To modify that, look in the code you pasted in Frame 1 of your animation. Find the commented line that says "//specify the width and height of the movie" and look at the two lines below it.

In the width field, change the value after width to reflect your animation's width. Likewise, in the height field, change the value after height to reflect your animation's height:

 

 


 

The above note concluded this tutorial. If you are interested in seeing how my animation in this tutorial was created, click the download fla link below:

Getting Help

If you have questions, need some assistance on this topic, or just want to chat - post in the comments below or drop by our friendly forums (where you have a lot more formatting options) and post your question. There are a lot of knowledgeable and witty people who would be happy to help you out

Share

Did you enjoy reading this and found it useful? If so, please share it with your friends:

If you didn't like it, I always like to hear how I can do better next time. Please feel free to contact me directly via e-mail, facebook, or twitter.

Brought to you by...

Kirupa Chinnathambi
I like to talk a lot - A WHOLE LOT. When I'm not talking, I've been known to write the occasional English word. You can learn more about me by going here.

Add Your Comment (or post on the Forums)

blog comments powered by Disqus

 

 




SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple.