Learn how to create the ActionScript to load a random Flash Movie onto a HTML web page.

Home • Members Tutorials Forum iSnapChat Contact Us 


Flash Tutorials


Loading a Random Flash Movie


Free Flash Tutorial

Step 3    <<   Previous      Intro   1   2   3    >>      


Step Three: Creating the ActionScript

  1. Select: Frame 1
  2. Open the Actions Panel: Window > Actions (F9)
  3. Important Note: Make sure that you can see Actions - Frame at the top of the Actions Panel:

    The Actions Panel has Actions - Frame in the top corner.

  4. In the Actions Panel if Script Assist is on, Switch: Script Assist Off
  5. Note: To see if Script Assist is on or off go to the Action Panel's Side Menu Button:   

    Script Assist is On when ticked: (remove the tick)

    Cross Ref: If you are not sure what Script Assist is or how to switch it on and off see the short Tutorial: Actions Panel

  6. Type (or Copy & Paste) the following Actionscript into Actions Panel:
  7. // 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);

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

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

    Note: This will load only one of your random Flash Movies. Just to check that the random load is working test your Movie several times.

    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 = "http://www.yourwebsite.com/movies/" + myRandomNumber + ".swf";

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


Please indicate what you thought of this tutorial 
10 is the best: 
10 9 8 7 6 5 4 3 2 1


Step 3    <<   Previous      Intro   1   2   3    >>      

29833 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.