Lesson 12 - Load Movie

Just like HTML, Flash has ways of changing pages. In HTML, this is done with the anchor tag <a>. Flash has an action that is identical to the anchor tag. This action is called getURL.

getURL

All of the actions we've learned so far affect the timeline. There is another action that let's us link to pages just like the anchor tag. We apply the action getURL the same way we do other actions, to a frame or button. It is written like this:

getURL("http://www.mysite.com","target");

Here is an example of a button linking to an link on a new page:

on(press){
  getURL("http://www.toolsj.com","_blank");
}

If you want to load your page in the same window as your flash, just write in the link and close the parenthesis without anything for the target.

loadMovie

getURL can be useful for linking to external pages, but Flash has a far more effective and interesting way to load files. This function is the loadMovie action.

The loadMovie function is fairly complex, but extremely powerful. It allows you to take an empty movieclip and load another external Flash movie into it. This action is applied to a button or frame like every other action. It is written like this:

targetmovieclip.loadMovie("flashmovie.swf");

To use loadMovie, you have to have a couple things. First you need a Flash movie to load. To make a flash movie, take any working file and simply publish it (file > publish). This will create a movie version of your working flash file. Working files have the extension ".fla" and movies have the extension ".swf". Now we have a flash movie to load.

Next, we need to create a blank movie clip to be our target. To create a blank movie clip, simply go to Insert > New Symbol and choose movie clip. This will put you inside the movieclip to edit it. Since you want it blank, just click back to the stage without doing anything to it. Now you have that empty movie clip in your library.

Now we want to drag our empty movie clip out of our library. You will notice that it displays as a circle with a cross in it. Because we target movie clips by instance name, we will have to give this movie clip and instance name. Click on the target and name it in the properties panel.

Flash will load the upper right corner of your flash movie to the center of your empty movie clip, so move the center to where you want the upper right corner of your flash movie positioned.

Now we have a blank movie clip as our target (I usually even give this movie clip the instance name "target"). When you use the loadMovie action, you will essentially replace the empty timeline in your movie clip with the timelines in the flash movie you are loading in. If I was using a button to trigger my event, my action could look like this:

on(press){
  target.loadMovie("mymovie.swf");
}

It is that simple. Because loadMovie automatically replaces whatever is in the target movie clip with the movie you are loading, you can keep loading different movies to the same target, and each time it will replace the last loaded movie with the new one.

unloadmovie

In the event that you want to empty out a movieclip completely, you can use the unloadMovie action. It works just like loadMovie:

targetmovieclip.unloadMovie();

Since we don't have any parameters, there is nothing with the parentheses. Now you can make pages as versatile and interesting as HTML in Flash.

Back to Lesson 11 . On to Lesson 13