How to use Flash to load random images onto a web page.

Home • Members Tutorials Forum iSnapChat Contact Us 


Flash Tutorials


Click by Click: Loading a Random Flash Movie

See Full Version: This is a shortened click by click version of a: Full Length Tutorial


Free Flash Tutorial


This tutorial will show you how to load a random Flash Movie onto your web page. Every time a user returns to your page a new Flash Movie will display. This can be used to make your site look fresh and dynamic or to deliver different messages or ads campaigns.

I sometimes use this system to deliver Flash Movies in the head section of the pages in this site. It is very powerful as the same Flash Movie can be used to control all the pages on the site. If I want to change the Flash Movies that are displayed I simply delete my current group of Flash Movies and replace them with the new ones. If I want to change the number of random Flash Movies that are displayed all I need to do is change a single line of ActionScript and upload the new version. That single change may take only a few minutes but it will effect thousands of pages on the webwasp site. There is no need to change any HTML on individual pages.

The ActionScript used in this tutorial is very simple and consists of only four lines. So for those of you wary of ActionScript, don't worry.

For this tutorial you'll be making something like this:

Example: Download the Flash file Beg 042

To change the Movie press your Browser's Refresh button (F5).

Note: I have loaded a series of 6 Flash Movies. The Flash Movies are displayed at random so occasionally the same Flash Movie will be displayed twice in a row. Obviously the more Flash Movies in your series, the less likely they are to repeat.

Click by Click: If you would like to view this tutorial without all the notes: Click by Click

Step One: Getting the Movies Ready

Movie Dimensions
It is best (although not essential) if your Flash Movies are all the same size. Otherwise you may get some unexpected results.

How Many Movies?
You will need to collect together a number of Movies. How many is up to you. It is even possible to have only 1 and add more at a later date.

File Location
You will need to place them all into a single folder on your computer.

Naming the Movies
Name all your Flash Movies numerically from 1. Do not use names like 01.

Step Two: Setting up the Master Flash Document

  1. Open a New Flash Document: File > New (Ctrl N)
  2. If the General Tab is not selected, select it: General Tab
  3. Select Flash Document: Flash File Flash File (ActionScript 1.0 or 2.0 not 3.0)
  4. Click: OK

  5. Go to: Modify > Document (Ctrl J)
  6. Set the size: 250 x 80 (or what's appropriate for your Flash Movies)
  7. Click: OK

  8. Save your file into the same folder as that of your other Flash Movies: File > Save

Step Three: Creating the ActionScript

  1. Select: Frame 1
  2. Open the Actions Panel: Window > Actions (F9)
  3. In the Actions Panel if Script Assist is on, Switch: Script Assist Off
  4. Type (or Copy & Paste) the following Actionscript into Actions Panel:
  5. // Sets the number of Flash Movies in the random sequence
    // IMPORTANT: Set this number to how many Flash Movies you have

    var myMovieSequence = 6;

    // Creates the random number:
    var myRandomNumber = Math.floor(Math.random()*myMovieSequence)+1;

    // Creates the full Flash Movie name like: 1.swf
    var myMovieName = myRandomNumber + ".swf";

    // Loads the random Flash Movie:
    loadMovieNum(myMovieName, 0);

  6. Change  myMovieSequence to the number of Flash Movies in your sequence. Mine is: 6

  7. Test your movie: Control > Test Movie (Ctrl Enter)

    Important: In Test Mode if you have not saved your Flash file into the same folder as your Flash Movies your movie will not work. When you upload your files to the Internet then the HTML page must be in the same location as the Flash Movies and the location of the Master Flash Movie becomes irrelevant. If you want to use your Flash file in multiple web pages and load Flash Movies form one location you will need to specify an absolute address like this:

    var myMovieName = "" + myRandomNumber + ".swf";

I hope you have found this useful. If so perhaps you could recommend this site to others and link to webwasp!

This is a quick reference version of a full length tutorial: Full Length Tutorial

17300 visitors to this page since 30 Oct 07

Phil Schulz's Facebook Profile
Webwasp is Phil Schulz's baby. You are welcome to contact me or become my Facebook friend: Click here

 Top of Page HomeMembers Tutorials Forum iSnapChat Contact Us 
 All material on this site is protected under international copyright © law. DO NOT reproduce any material from this site without written permission. Please ask as permission is often granted.