Load Movies into Levels and Movie clips

The aim of the tutorial is to learn how to use Levels to load several Flash movies (or Jpegs) simultaneously into a single shockwave file (swf). How to switch between one Flash movie and another without loading a new web page. How to load a new movie into a movie clip of a pre-existing movie. To do this we need to look at the following ActionScript keywords:

  • loadMovieNum
  • unloadMovieNum
  • _root
  • _level
  • loadMovie
  • unloadMovie
Example of loading different movies into different levels.

Levels

Levels enable you to play several Flash movies one on top of another or to reload new movies into the same space that the original movie was playing. When you play a Flash movie it automatically plays in level zero. If you want you can simply play one movie over top of the other. Subsequent movies would load into level one, two, three etc.

Start movie file name: KWs-201a__Load-Movie_Start.swf

This is the entire content of the example movie above. All the other content loads from separate movies. The ActionScript in frame 1 automatically loads the next movie:

loadMovieNum("KWs-201b__Load-Movie_1b.swf", 1);

This loads Movie 1B into level 1. The original Start movie continues to play underneath on level 0.

Note: Always include the file extension (.swf) otherwise it will not work. Also all files need to be in the same folder as well as the web page.

Note: There is a small intro tweened animation and the ActionScript in frame 25 is: stop();
For more info on Tweening see: Tweening   Tween within Tweens

Level One Movie

This is the movie that automatically loads into level one. File name: KWs-201b__Load-Movie_1b.swf

Background

Note: The movie above has a gray background, not blue. The background colour of a movie does not load. It always loads with a transparent background. If it was not transparent you could not see the movie underneath, which would be a bit pointless!

Alignment

The size of the movie (in pixels) and length of the Timeline do not matter. No matter what the size of your movie all the movies will align to the top left corner. When you use loadMovieNum you have no control over this but you do have control over the position of objects and symbols within the individual movies.

Note: It is always easier if you make the movies the same document size, this makes it easier to position objects so that they will align.

Reloading a Movie into Level 1

The Home Level 1 button reloads Movie 1b back into level one. The button has the following ActionScript attached:

on (release) {
    loadMovieNum("KWs-201b__Load-Movie_1b.swf", 1);
}
  • The number 1 right at the end of the line sets the level.
  • The KWs-201b__Load-Movie_1b.swf is the file name (including the file extension .swf)  
  • If possible keep your file names short - not like me!!!

Loading a new movie into Level 1

When you click the Next Level 1 button the previous movie 1b is unloaded and movie1c is loaded . The button has the following ActionScript attached:

on (release) {
    loadMovieNum("KWs-201c__Load-Movie_1c.swf", 1);
}

Note: There is no code to unload the previous movie. You cannot have more than one movie in any level so any existing movie is automatically unloaded.

The next movie that loads into Level 1. File name: KWs-201c__Load-Movie_1c.swf

Loading a new movie into Level 2

on (release) {
    loadMovieNum("KWs-201d__Load-Movie_2.swf", 2);
}
The Level 2 Movie. File name: KWs-201d__Load-Movie_2.swf

Unloading the movie from Level 2

This ActionScript clears any movie from the specified level, you do not need to name the movie:

on (release) {
    unloadMovieNum(2);
}

Loading a new movie into Level 0 and clearing all other Levels

This unloads all movies! It does not matter what level they are on. It then loads a new movie into level 0.

on (release) {
    loadMovieNum("KWs-201e__Load-Movie_0.swf", 0);
}
The new Level 0 Movie. File name: KWs-201e__Load-Movie_0.swf

Loading the original Start movie back into Level 0

This places the original Start movie back into level one:

on (release) {
    loadMovieNum("KWs-201a__Load-Movie_Start.swf", 0);
}

Because the Start movie loads Movie1b into level 1 automatically from the ActionScript in the Timeline. The script above:

  •  Unloads level 0 (And all other levels)
  •  Loads the: Start movie into level 0 which in turn ...
  •  Automatically loads: Movie1b into level 1

Jpegs

Although all the movies above are Flash shock wave files (swf) you can use exactly the same code to load Jpeg pictures. The ActionScript would look like this:

loadMovieNum("myImageName.jpg", 1);

The advantage of loading Jpegs is that if you have a site which has many pictures the Flash swf would get very large and take ages to load on the web page. If you use levels the Jpeg loads as they are needed. If you have 200 Jpegs and the viewer only wants to see 3 of them, why wait for 200 to download.

The disadvantage is that they will all align in the top left corner. If you don't want that, place them in an empty Flash movie, locate them in the position you want and load the Flash movie into a level.

Gifs and Pngs cannot be directly loaded into a level. You would need to place them in a Flash movie and load the swf file.

Important Note: When you save your Jpeg make sure the 'progressive' option is not selected as you cannot load progressive Jpegs into Levels.

Controlling different movies: _root Vs _level0

You use one movie to control another. To do this you must be very careful with the use of _root and _level0

What's the difference?

If you only have one movie loaded into level 0 there is no difference at all. For example:

on (release) {
   
_root.myMC.web.gotoAndStop(1);
}
or
on (release) {
   
_level0.myMC.web.gotoAndStop(1);
}

If the movie concerned is loaded into level 0, the above ActionScript will do the same thing.

But if the movie is loaded into level 1 they are quite different:

_root will go to the root directory of the movie in level 1.

_level0 will go to the root directory of the movie in level 0.

In other words:

_root always refers to the root directory of the movie where the command originates from, irrespective of what level it may be on.

_level0 always refers to the root directory of the movie in level 0 irrespective of where the command comes from.

If you want to learn more about paths look at the beginners tutorial: Target Paths

loadMovie

Loadmovie is very similar to loadMovieNum but you guessed it not quite the same. LoadMovie does not load movies into levels but loads one movie inside another movie.

To use loadMovie you place a blank movie clip on the stage of original movie. This movie clip needs an instance name.

The ActionScript syntax is:

loadMovie("nameOfMovie.swf", _root.instanceNameOfBlankMC);

If I placed a blank movie clip on stage with an instance name: blankMC

I could then place the following ActionScript in frame one of my sample movie:

loadMovie("KWs-061__Load-Movie_1b.swf", _root.instanceNameOfBlankMC);

UnloadMovie

The following ActionScript will unload the movie. Note you don't have to name the movie you wish to unload, you only use the instance name of the movie clip.

unloadMovie(_root.instanceNameOfBlankMC);

Action Panel

You will find the loadMovieNum and loadMovie under: Plus > Actions > Browser/Network > loadMovie

In Normal Mode look at the options above the ActionScript and:

For loadMovieNum select: Levels

For loadMovie select: Target

The Actions Panel

The only thing to do now is to go and try to load various Movies and Jpegs. Hopefully you should now find this straight forward. Good luck.


Close    To Top
  • Prev Article-Flash:
  • Next Article-Flash:
  • Now: Tutorial for Web and Software Design > Flash > Basic > Flash Content
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Geek Tutorial
     

    Blogging Tutorial

      RSS Tutorial
      Podcasting Tutorial
    Graphic Design Tutorial
      Coreldraw Tutorial
      Illustrator Tutorial
      3D Tutorials
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial/ Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial/ Articles
     

    XML Style

      AJAX Tutorial
      XML Mobile
    Flash Tutorial/ Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial/ Articles
      Linux Tutorial
      Symbian Tutorial
      MacOS Tutorial
    Personal Tech
      Hardware Tutorial
      Software Tutorial
      Online Auction