Loading Random Movies
      by kirupa - 25 January 2004

Do your animations seem to get boring when viewed repeatedly? Do you want to give the impression to your visitors that you update your site regularly but you don't feel like doing all the work that goes along with updating regularly? You may need to add some randomness to your design. A cool effect that you can see when you visit various portions of this site and this tutorial is randomly loading movies.

Randomly loading movies basically load a typical movie file, but instead of playing the same content, they load a random movie file from somewhere on your server and play them. The chances are, each time someone views your animation, a random movie would load. That gives your visitor the notion that your site changes - indirectly.

The following animation is an example. Keep reloading this page to see various other movie effects. The best thing is that each movie effect is actually an external SWF file located on the server. This tutorial will explain how to load a random external SWF file into your animation:

[ reload this page to see a different movie ]

Here's How
The following steps for Flash MX/2004 will help you to create your own animation and load random movies into it:

  1. First, create a new movie, and set its width and height to be 300 by 200 pixels. Also, set your frame rate to 25.

  2. Once you have setup your movie, draw a small circle using the Oval Tool. Once you have drawn a small circle, select the circle and press F8. Don't worry about the circle's colors, etc. It won't matter as you will find out later.

  3. The Convert to Symbol dialog box will appear. Select Movie Clip and press OK.

  4. Now, select your newly converted circle/movie-clip and look in the Properties panel on your bottom left. In the text field marked <Instance Name> enter the word movieTarget.

  5. From the same Properties panel, in the boxes marked X: and Y: enter a 0. This will place your movie clip in the top-left corner at the origin.
     
    Your info panel should look like the following image:

[ how your Properties panel should look like ]
  1. Select the first frame in your timeline and press F9 to display the Actions-Frame window. Copy and paste the following code:

filename = ["circular.swf", "vibration.swf", "random_movement.swf"];
path = "//www.kirupa.com/developer/actionscript/animation/";
i = filename.length;
k = Math.floor(Math.random()*i);
loadMovie(path+filename[k], movieTarget);
[ add the following code to the Actions-Frame window ]
  1. Preview the animation in your browser by going to File | Publish Preview | HTML.

Now, let's find out more about the ActionScript that causes your animation to load a random movie from an external location. Onwards to the next page!

 

 



SUPPORTERS:

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