Loading Flash Movies Flash

Long sequences of animation in Flash naturally require the preloading described in the previous section to guarantee smooth playback. But traditional information-based Web sites done in Flash require a different kind of download management. Suppose you’re building a Web site with three sections: products, staff, and company history. Each section is roughly 100KB in size. In a normal Flash movie, you’d place those sections in a sequential order on the main movie timeline. The last section you place on the timeline would, of course, be the last section to download. Might sound fine so far, but here’s the problem: What if the section that appears last on the timeline happens to be the first and only section the user wants to see? They’d have to wait for the other two sections to download before they could view the one they want but they don’t even want to see the other two sections, so really they’re waiting for nothing. The solution to this problem is the loadMovie action.

loadMovie provides a means of inserting one or more external .SWF files into a Flash movie (whether that movie resides in a browser or on its own in the standalone player). loadMovie can be used to replace the current movie with a different movie or to display multiple movies simultaneously. It can also be used, as in our company Web site example, to enable a parent movie to retrieve and display content kept in independent .SWF files on a need-to-retrieve basis (similar to the way a frame in an HTML frameset can call external pages into different frames).

Basic overview of Flash site architecture
There are two primary ways to produce and distribute straight Flash content on the Web: (a) create several small .SWF files, each one living within a standard HTML page on a Web site; or (b) create one HTML page that hosts one main .SWF file that loads additional content through the Flash Player plug-in. Figure below illustrates these alternatives.

The diagram on the left illustrates a Web site that uses multiple HTML pages, each with an individual .SWF file. The diagram on the right shows a Web site that uses one HTML page (or frameset) that has one primary .SWF file, which loads other .SWF files as needed.

The diagram on the left illustrates a Web site that uses multiple HTML pages,

If you decide to break up your Flash movies across several HTML pages, your Web visitors will experience:

  • Short download times for each page
  • Easier bookmarking of discrete sections of your Web site
  • Abrupt transitions between each section of the Web site
  • However, if you use one primary Flash movie in one HTML page (or frameset), your visitors will benefit from:
  • Short download times for each .SWF file (download times vary with file size)
  • Seamless integration of new Flash content
  • Controllable transitions between .SWF asset changes Which method should you use for your Flash projects? The answer depends on the specifics of each Web project. You may decide to use a combination of both methods, especially for larger sites that use several Web technologies (QuickTime, Flash, RealPlayer, Windows Media, and so on). In either scenario, you can use the loadMovie action to manage Flash content more easily.

Where are the multiple movies stored?
You may already be wondering how these newly loaded movies are managed relative to the original movie. Flash uses the metaphor of levels to describe where the movies are kept. Levels are something like drawers in a cabinet; they are stacked on top of each other, and can contain things; you can place things in any drawer you like, but once a drawer is full you have to take its contents out before you can put anything else in. Initially, the bottom level, referred to as _level0 (“Level 0”), contains the original movie. All movies subsequently loaded into the Flash Player must be placed explicitly into a target Level. If a movie is loaded into Level 1 or higher, it appears visually on top of the original movie in the Player. If a movie is loaded into Level 0, it replaces the original movie, removing all movies stored on Levels above it in the process. When a loaded movie replaces the original movie, it does not change the frame rate, movie dimensions, or movie background color of the original Flash stage. Those properties are permanently determined by the original movie and cannot be changed.

Loading an external .SWF file into a movie
A new movie is imported onto the main movie Stage when a loadMovie action is executed. Here’s how to make a button click load an external movie named movie2.swf:

  1. Place a Button instance on the Stage of your main movie. Bring up the Actions Panel for the Button by selecting the instance and pressing Ctrl+Alt+A (PC) or Option+Command+A (Mac). Make sure the Actions Panel is in Normal Mode
  2. With the Actions Panel in Normal Mode, you can clearly see the options and settings of the loadMovie action.

    With the Actions Panel in Normal Mode, you can clearly see the options and settings of the loadMovie action.

  3. Click the plus (+) button in the top-left corner of the Actions Panel, and select Basic Actions➪Load Movie. Type movie2.swf (or your external .SWF file name) into the URL text field. The URL text field contains the network path to the movie file that you want to load. That path must be specified relative to the location of the page that contains your main movie, not relative to the location of the movie itself.
  4. Select the Level option in the Location menu, and type 1 into the Location text field. This instructs Flash to load movie2.swf into _level1. If there had already been a movie loaded into _level1, it would automatically have been replaced by movie2.swf.
  5. Click OK.

How Flash handles loaded movies of differing sizes
A movie loaded onto Level 1 or above that is smaller than the Level 0 movie is positioned in the top-left corner of the Stage. In this situation, elements on the Level 1 movie’s Stage are displayed even when they go beyond the bottom and right dimensions of the Level 1 movie. To prevent objects from being displayed off Stage you would have to create a curtain layer above all the other layers in the Level 1 movie that covers up the work area (the space outside the movie’s Stage). Movies loaded onto Level 0 that are smaller than the original Level 0 movie are automatically centered and scaled up to fit the size of the original movie (the manner in which they are scaled depends on the Scale setting in the Publish settings). Movies loaded onto Level 0 that are larger than the original Level 0 movie are cropped at the right and bottom boundaries defined by the original movie dimensions.

Placing, scaling, and rotating externally loaded .SWF files
Especially when your movies are different sizes, it’s not very convenient to have newly loaded movies dropped ingloriously in the top-left corner of the Stage. To give you more flexibility with the placement, rotation, and scale of your loaded movies, Flash provides the capability to load a movie into a Movie Clip instance.

So far, this may not make a whole lot of sense. Loading a movie into a Movie Clip instance seems like a strange feature at first, until you find out what it can do then it seems indispensable. The easiest way to understand what happens when you load a movie into a Movie Clip is to think of the loadMovie action as a Convert Loaded Movie-to-Movie Clip action. When a movie is loaded into a Movie Clip instance, many attributes of the original Movie Clip instance are applied to the newly loaded movie:

  • The timeline of the loaded movie completely replaces the original instance’s timeline. Nothing inside the original Movie Clip (including actions on keyframes) remains.
  • The loaded movie assumes the following Properties from the original Movie Clip instance:
    • Name
    • Scale percentage
    • Color effects, including alpha
    • Rotation degree
    • Placement (X and Y position)
    • Visibility (with respect to the _visible property)
  • Any onClipEvent handlers (and actions within them) that are written for the original Movie Clip instance will still be available (and executing) on the loaded Movie.

We like to refer to Movie Clips that are used to load other movies as Movie Clip holders. Usually, you will load movies into empty Movie Clips that don’t have any artwork or actions. However, because you’ll need a physical reference to the actual area your loaded movie will occupy on the Stage, it’s useful to create temporary guides or artwork that indicate this area. The following steps show you how to create a Movie Clip holder, and how to load an external .SWF file into it.

  1. Create a new Movie Clip symbol (Ctrl+F8 or Command+F8) that contains a square or rectangle. This shape can be drawn with the Rectangle Tool. The shape should have the same dimensions as the external .SWF movie’s Stage, as defined in the Movie Properties dialog.
  2. Place the shape so that its top-left corner is at the 0,0 X,Y coordinate. To do this, select the shape and open the Info Panel. Click the top-left corner of the bounding box diagram, and type 0 in the X and Y fields. Make sure that you press Enter after you type each zero.
  3. Go back to the Main Timeline (Scene 1), and place an instance of this Movie Clip on the Stage. In the Instance Panel, give this Movie Clip instance the name movieHolder. Position it where you want the external .SWF movie to appear. At this point, you can also tween, scale, or apply color effect to the instance as well.
  4. Add a loadMovie action to a Button instance or keyframe.
  5. specify the loaded movie’s network path and filename in the URL field. Select the Target option in the Location menu. Type movieHolder into the Location field. The field specifies the name of the Movie Clip instance into which you want to load your external .SWF file.
  6. Save the Flash movie file and test it. Your .SWF file’s top-left corner will match the top-left corner of the original Movie Clip instance.
  7. You may have noticed that there was a quick flash of the original Movie Clip’s rectangle artwork before the external .SWF loaded into it. To avoid this, go into the Movie Clip symbol for movieHolder and turn the layer containing the rectangle artwork into a Guide Layer. Guide Layers will not export with the .SWF file.
  8. If you need to add functionality to the loaded movie, then use ActionScript to control the new loaded movie instance. The next section shows you how to communicate with loaded movies.

Communicating between multiple movies on different levels
After a movie or two are loaded onto different levels, you may want each timeline to control the other, just as Movie Clips can control each other. To communicate between different Levels, you simply need to address actions to the proper Level.
The method for addressing a Level that controls a timeline on a different Level is identical to the method for addressing a Movie Clip target that controls the timeline of another Movie Clip instance, except for one small change. You have to indicate the name of the Level you want target rather than the name of the Movie Clip. Level names are constructed like this: First, there’s an underscore (_), then there’s the word level, and then there’s the number of the Level that you want your Action to occur on.

This tells the movie loaded onto Level 1 to go to frame 50:


This tells the main movie timeline to go to frame 50:


You can also target Movie Clips that reside on the timelines of movies on other levels. Here’s an example:


This sends a play() action to the Movie Clip named products on the timeline of the movie loaded onto Level 3.

Unloading movies
Even though a movie loaded into an occupied Level (one that already contains a loaded movie) will automatically be removed before the new movie is displayed, the transition can be choppy. To ensure a smooth transition between movies, or to lighten the memory required by the Flash player, you can explicitly unload movies in any Level or Movie Clip target by using the unloadMovie action. The only option for unloadMovie is the path to the desired location (for example, _level1, _root.instanceName).

loadMovie as a method or action for Movie Clip targets
Both loadMovie and unloadMovie can be used as either an ActionScript method or action for Movie Clip targets. What does this mean? You can apply actions in Flash 5 in two ways: as methods of a Movie Clip Object (or some other ActionScript Object), or as a stand-alone action.

As an action, loadMovie and unloadMovie start the ActionScript line of code. When you use actions in this manner, the target of the action is specified as an argument (option) within the action. In the following example, the file external_1.swf is loaded into Level 1:

loadMovie (“external_1.swf”, “movieHolder”);

As a method, actions are written as an extension of the object using the action. Therefore, the target is already specified before the action is typed. The same example shown previously could be rewritten as a method of the movieHolder Movie Clip Object:

movieHolder.loadMovie(“external_1.swf”); or _root.movieHolder.loadMovie(“external_1.swf”);

Because we have specifically referenced the movieHolder instance as an object, the loadMovie action (now a method) knows where to direct the loading of external_1.swf.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Flash Topics