|
Free Open Book
Macromedia Flash 8 Bible |
Loading Flash MoviesA long sequence of Flash animation or any Flash movie that contains many internal assets naturally requires the preloading described in the preceding 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 100 KB in size. In a normal Flash movie, you'd place those sections in a sequential order on the Main Timeline or create a scene for each of them. 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 users want 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 stand-alone 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 ArchitectureYou can produce and distribute straight Flash content on the Web in the following two primary ways:
Figure 28-15 illustrates these alternatives.
Figure 28-15: 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, or iframe) that has one primary .swf file, which loads other .swf files as needed. If you decide to break up your Flash movies across several HTML pages, your Web visitors will experience the following:
However, if you use one primary Flash movie in one HTML page (or frameset), your visitors will benefit from:
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 (Apple QuickTime, Macromedia Flash and Shockwave, Real Systems RealOne, Microsoft Windows Media, and so on). In either scenario, you can use the loadMovie() action to manage Flash content more easily.
Storing Multiple MoviesYou may already be wondering how these newly loaded movies are managed relative to the original movie. Macromedia 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 in ActionScript as _level0 ("Level 0"), contains the original movie, the first movie that loads into the Flash Player. 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 determined by the original movie and cannot be changed, unless you load a new HTML document into the Web browser. You can also use a getURL() action to load a new .swf file into the browser to "reset" the Flash Player.
Loading an External .swf File into a MovieA new movie is imported into the Flash Player when a loadMovie() action is executed. In the following steps, you'll learn how to make a button click load an external movie named bandwidth.swf.
You can apply this technique to any .swf file that you wish to load into another Flash movie. You can make a series of buttons, each one loading a different .swf file. You can modify the click() method of the oLoader object to switch the URL of the loaded movie, depending on which button is pressed.
When a movie is loaded above any other movie (including the main movie), the Buttons and Movie Clips in the movies on lower levels will continue to be active, even though they may not be visible. To prevent this undesired behavior, you need to send movies on lower levels to an idle or blank frame where no buttons are present. Do that by adding a goto action before your loadMovie() action that sends the current movie to the idle frame. This technique is known as "parking" the movie. If you have to park multiple movies, you'll need to know how to communicate between movies on different levels. We will discuss this shortly. How Flash Handles Loaded Movies of Differing DimensionsA movie loaded onto Level 1 or higher that is smaller in width and height than the Level 0 movie is positioned in the top-left corner of the Stage. You may have noticed this phenomenon in the last section. In this situation, it is possible to have elements that are off-stage within the loaded .swf file. However, when you load a smaller .swf file Stage into a larger .swf file Stage, these off-stage elements are displayed on the Stage of the larger .swf file. To prevent objects from being displayed, you would have to create a curtain layer or a Mask 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 Flash MoviesEspecially when your movies have different width and height dimensions, 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, ActionScript provides the capability to load a Flash movie file (.swf) 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:
We like to refer to Movie Clips that are used to load other movies as Movie Clip holders. Usually, you load movies into empty Movie Clips that don't have any artwork or actions. However, because you may need a physical reference to the actual area that your loaded movie will occupy on the Stage, it's useful to create temporary guides or artwork that indicates this area.
The following steps show you how to create a Movie Clip holder and how to load an external .swf file into it. You will use the same file you created in the previous section.
To avoid seeing the rectangle artwork in your final Flash movie, go into the Movie Clip symbol for holderClip and turn the layer containing the rectangle artwork into a Guide layer. Guide layers will not export with the .swf file. Also, add a new empty layer on the holderClip timeline. This empty layer can be above or below the original artwork layer.
If you need to add functionality to the loaded movie, 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 LevelsAfter 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 to target rather than the name of the Movie Clip. Level names are constructed such as this: First, there's an underscore (_); then there's the word level; 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: _level1.gotoAndStop(50); This tells the Main Timeline to go to frame 50: _level0.gotoAndStop(50); You can also target Movie Clips that reside on the timelines of movies on other levels. Here's an example: _level3.mcProducts.play(); This sends a play() action to the Movie Clip named mcProducts on the timeline of the movie loaded onto Level 3. Unloading MoviesTo lighten the memory required by your Flash movies in the Flash Player or to clear the loaded movie from the Stage, 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 for Movie Clip TargetsBoth loadMovie() and unloadMovie() can be used as either an ActionScript method or action for Movie Clip targets. What does this mean? You can apply some actions in ActionScript in two ways: as methods of a MovieClip object (or some other ActionScript object, as we have discussed in previous chapters) 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 the mcHolder instance:
loadMovie("external_1.swf", "mcHolder");
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 holder_mc MovieClip object:
mcHolder.loadMovie("external_1.swf");
or
_root.mcHolder.loadMovie("external_1.swf");
Because we have specifically referenced the mcHolder instance as an object, the loadMovie() action (now a method) knows where to direct the loading of external_1.swf.
|
Main Menu |
| 500 Juegos Gratis | 500 Giochi Gratis | 500 Jeux Gratuits | 500 Jogos Gratis | 500 Kostenlose Spiele |