|
|||
| week 09d - final project, audio, drawing, loadmovie, preloader | |||
loadMovie: |
loading parts as needed, rather than all at at the beginning As your Flash movies have more assets like sounds and video they may become too large for a reasonable download time. But you can handle this by breaking the movie up into parts so they can be loaded as needed rather than at the beginning. This way, the user experiences load times only for the parts they are seeing as they see them. The simplest example of this is loading a JPEG image into an existing movieClip. Here is the code to do this:
Note that this code replaces the movieClip in the instance called "aClip", and replaces it with the JPEG. The instance retains whatever properties and scripts that instance already had, but nothing that was inside the old movieClip is retained. NOTE: When using loadmovie(), the URL to the image or .swf file to be loaded is relative to the location of the HTML page that contains the loading movie. So even though the load_movie.swf is in the same swfs directory as the "IMG_0418.jpg", the HTML page that contains load_movie.swf is one level up. So the URL must be relative to this HTML page, as in "swfs/img_0418.jpg". See also the loadSound() method for sound objects (book, page 780), which allows you to load MP3 files and stream them.
|
|
| loadMovie() : | loading a .swf The loadMovie() method can also be used to load an external .swf into the current movie. Usually, the new swf is loaded in place of an existing movieClip, replacing the contents of the instance as described above. The code is similar to the above:
Note that any code in the new .swf must observe the same target paths for movieClips as the movieClip it replaces. For example, if the .swf made a reference to _root that worked when the loaded .swf was played on its own, that _root reference would no longer work, because it would refer to _root of the movie that loaded it, not its own top level. It's also possible to replace the entire contents of the current movie. This is accomplished by replacing the _root target:
|
|
| a good preloader : | scale a clip and advance an animation to show percentage loaded It is usually a good idea to provide the user with an indication of how much of a movie is loaded. It's also good practice to make sure code does not run that depends on parts of the movie that have not loaded yet. There are many approaches to preloaders, and the textbook has a good one. This code checks to see how many bytes (rather than frames) of the .swf have loaded, and displays this graphically by adjusting the scale of a graphic in proportion to the percentage of bytes loaded.
Here's the code:
Testing the preloader The testing of preloaders can be tricky because when loading the file locally, there is not enough delay to see the preloader work. You can test what the actual behavior will look like by using the Flash's "Simulate Download" feature. After the initial testing of the swf (CONTROL>TEST MOVIE), in the menu for the SWF select VIEW>SIMULATE DOWNLOAD . To set the download rate (i.e. connection speed) use the VIEW>DOWNLOAD SETTINGS menu and select the connection speed.
|
| all materials on this web site © copyright 2004, Philip van Allen |
top |