• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Connecting the Two Files

Taking my own advice from Lesson 8, I decided to separate Upper and Lower Hell into two files to make the project more modular and prevent users from having to download both at once. To accomplish this modularity, you'll use a variant of the loadMovie() action used in Lesson 8. In this case, though, instead of loading the movie into a container movie clip, you will load the movie into the main timeline, which effectively flushes the original movie out of the Flash player altogether.

Open upper.fla from Lesson 11's Start folder.

You could begin with either FLA, as each has a button pointing to the other, and their scripts will mirror each other as well.

Select the button with the down-pointing arrow, and enter the following script in the Actions panel:

							on (release) {

This script is slightly different from the one you wrote in Lesson 8, so let's take a moment to compare them. In Lesson 8, the loadMovie script you wrote looked (at its simplest) as follows:


In this script, the loadMovie() action loads a movie called sim_dsn.swf, and it loads it into an object (here, a movie clip) called container.

The present script differs in two ways. First, rather than loadMovie(), it uses loadMovieNum(). The loadMovieNum() action differs from the loadMovie() action in that it loads the movie into a level, rather than an object. Remember that when you first open a SWF, it is at level 0, which represents the main timeline of that movie. If only one SWF movie is loaded, then the player has only one level: 0. Using the loadMovieNum() action, it is possible to load a movie into a different level, so that for example you could load a SWF into level 1, which would stack it above the SWF in level 0 in the Flash player. Each movie would have its own main timeline.

The second difference between the two scripts is related: Whereas the second parameter of the loadMovie() action (in this case, "container") is the proper name of an object, listed in quotes, the second parameter of the loadMovieNum() action is a number, not in quotes, representing the level into which you wish to load the movie.

In this particular script, when you load lower.swf into level 0, it replaces the current movie (because it is already in level 0). So while it is possible to load movies so you have multiple SWF movies stacked in different levels, you are not doing that here. You are causing lower.swf to replace, rather than stack above, upper.swf. The reason for this is simple: The two movies don't interact with each other in any way, and the user never needs to have them both loaded at the same time. By replacing one movie with the other, you free up space in the user's computer's memory, and the script is quite simple as well.

Test the movie, but don't click the down-arrow button. Close the SWF and return to the FLA. Save and close the FLA.

For the loadMovie actions to work, you need upper.swf and lower.swf. But neither yet exists in the Start folder. In this step, by testing the movie, you generate upper.swf. Doing this after adding the load movie script makes it possible to test the load movie scripts in both movies, once you have added the loadMovie() action to lower.swf. This is because when you click the up button in lower.swf, it will look for upper.swf. If upper.swf doesn't exist, the loadMovie() action has nothing to load. When working with loadMovie(), you must remember to ensure that copies of all the movies actually exist in the locations specified in the loadMovie() action's parentheses.

Open lower.fla, select the up-arrow button, and enter the following script in the Actions window:

							on (release) {

As promised, the script on this button is a mirror copy of the one on the down button in Upper Hell. At this point, the movies are successfully linked.

Test the movie to generate a SWF. Click the up button to go to Upper Hell, and then click its down button to return to Lower Hell. When you are done, close the SWF and save the file.

Always test functionality every time you complete a task. Frequent testing helps troubleshooting because you inevitably find problems as soon as they are created, rather than later, when you have done several things that could be the culprit.



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint