Learning Flash: Preload External Flash Movies

Home Food Mates • Members Tutorials Forum Buy Templates Contact Us 

 


Flash Tutorials

   

Tutorial - Preload External Flash Movies with Movie Clips

Free Flash Tutorial


Step 4    <<   Previous      Intro   1   2   3   4    >>       >>   Webwasp Mates

 

Step Four: The Actions - Frame 2

  1. Right click on Frame 2 in the Layer: ActionScript
  2. Select: Insert Blank Keyframe (not frame)
  3. Add this code:

    // Create a Movie Clip to load the swf Movie into
    this.createEmptyMovieClip("myExternallyLoadedSWFMovieHolder", 0);

    // A variable to hold the name and location of where the external swf Movie is located

    var myVariable = "myMovie.swf";

    // Set the Movie's location on the Stage

    myExternallyLoadedSWFMovieHolder._x = 0;
    myExternallyLoadedSWFMovieHolder._y = 0;

    /* Set the Progress Bar to manual mode so that we can reset its value back to 0. We don't want it staring from 100 ! */

    myProgressBar.mode = "manual";

    // Reset the Progress Bar back to zero

    myProgressBar.setProgress(0, 100);

    // Show the Progress Bar

    myProgressBar._visible = true;

    // Create a listener object event.

    myProgressBarListener = new Object();

    // When the Progress Bar is complete and has preloaded the Movie, the listener will call and run this code below:

    myProgressBarListener = function (eventObject) {

    // Hide the Progress Bar now the Movie is loaded

    myProgressBar._visible = false;

    // This next section is optional.
    // If you wish to remain on Frame 2 and view the External Movie do nothing
    // Otherwise un-comment any of the options bellow:
    // Plays the Movie from Frame 2 onwards:
    // play();

    // Go to the next Frame:
    // nextFrame();
    // Go to the next scene but may not automatically play beyond the Frame 1 in the next scene:
    // nextScene();
    // Goes to a Frame Label or Frame number and Play:
    // gotoAndPlay("myFrameLabel");
    // gotoAndPlay(10);
    // Go to and stop at the Frame Label or Frame number:
    // gotoAndStop("myFrameLabel");
    // gotoAndStop(10);


    // closes the function
    };

    // Declares a listener that detects when the Progress Component has loaded the external Movie and is complete.
    // It will call the function myProgressBarListener when the external swf Movie has loaded

    myProgressBar.addEventListener("complete", myProgressBarListener);

    // Set up the Progress Bar Component variables
    // Set up the Progress Bar Component to polled when loading the Movie. It has to be set to polled to work

    myProgressBar.mode = "polled";


    // Set the preloader source to show the progress of the loader Component as it loads the external swf Movie

    myProgressBar.source = "myExternallyLoadedSWFMovieHolder";

    /* This is how we automatically load the external swf Movie. We call the load Movie Clip event and load the external swf Movie into the Movie Clip we created through ActionScript */

    loadMovie(_root.myVariable, _root.myExternallyLoadedSWFMovieHolder);

    // Stop the Movie at the frame until the Movie is loaded

    stop();

  4. Important:
    Make sure you change the name of the file to the name of your file:
    myMovie.swf

    Strange but True: It is the location of the web page and the Movie that is loading that is important not the location of this preloader Movie! If you wish to move this preloader Movie to a different folder you can. It can also be used several times on several different web pages as long as each time the web page is located in the same place as a Movie called:  myMovie.swf. Each version of the Movie  myMovie.swf could be a different Movie with different content!

    Usually the Main Content Movie would be in the same folder as the web page. If it is not you will need to type a target path like this:

    myLoader.contentPath = "images/myMovie.swf";

    You may also use a full URL like this:

    myLoader.contentPath = "
    http://www.webwasp.co.uk/images/myMovie.swf";

    Confused? If you get in a muddle the easiest thing is to have the Web Page, Preloader Movie and Main Movie all in the same folder.


Your Layers should now look like this:


That's it.

 

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

         

Step 4    <<   Previous      Intro   1   2   3   4    >>       >>   Webwasp Mates


Webwasp Community: Webwasp Mates & Dates

Why not try out webwasp's new community. Meet new people, find friends in your area: Webwasp Mates & Dates

30503 visitors to this page since Oct 05 •

 Top of Page Home Food Mates Members Tutorials Forum Buy Templates 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.