Managing Smooth Movie Download and Display


When Flash movies are played back over the Internet, they progressively download, meaning that the Flash Player plug-in shows as much of the movie as it can during download, even if the whole file has not been transferred to the user's system or browser cache. The benefit of this feature is that users start seeing content without having to wait for the entire movie to finish downloading.

Note 

Technically, a Flash movie file is not a streaming file format, but a progressive download file format, similar to an original Apple QuickTime 3 video movie. A progressive download can be viewed before the entire file has been received by the browser. Streaming file formats are never saved as actual files in the browser cache. You can't save a true streaming file, but you can typically save a shortcut or link to the file's location on the Web. Flash Communication Server video streams, for example, cannot be cached as a file on the user's system.

Nevertheless, progressive downloading has potential drawbacks. During download and playback, the movie may unexpectedly halt at arbitrary points on the timeline because a required portion of the movie has not yet downloaded. Worse yet, if you use several linked assets (that is, assets in the library that are set to export for ActionScript, such as components), by default the first frame of your Flash movie won't play until all of those assets have downloaded.

Thankfully, there's a solution. You can regulate the playback of the movie by using ActionScript code to prevent the movie from playing until a specified portion of it has downloaded. This technique is often referred to as preloading. A common preload sequence, or preloader, involves displaying only a short message, such as "Loading Please Wait," while the movie loads. Once the appropriate amount of the movie has been retrieved, the movie is allowed to play. ActionScript provides basic and advanced methods of producing a preloader. This section of the chapter shows you how to use the following three different internal actions (or methods) to check the download status of a Flash movie:

  • ifFrameLoaded(): This action has been around since Flash Player 3, and it enables you to check whether a specified frame label in the Flash movie has been downloaded by the plug-in. This is the simplest action to use to check a movie's download progress. If you are designing Flash Player 5 or later movies, this action is considered deprecated.

  • MovieClip._framesloaded and MovieClip._totalframes: Introduced with Flash Player 4, these properties can be checked on a Movie Clip timeline or the Main Movie timeline (Scene 1, Scene 2, and so on). _framesloaded returns the current number of frames that have downloaded into the plug-in, whereas _totalframes returns the number of frames that exist on the specified target timeline.

  • getBytesLoaded() and getBytesTotal(): These methods were introduced in Flash Player 5 ActionScript. The most accurate way to check the progress of a Flash movie download is to use these methods with other ActionScript code. You can use these methods for the following objects in ActionScript for Flash 6 movies: MovieClip (including loaded movies [.swf files] or JPEG images) and Sound objects that load MP3 files. You can also use these methods to check the download progress of PNG, GIF, and progressive JPEG images in Flash Player 8.

Note 

Flash Player 7 introduced a new method of monitoring the load progress: the MovieClipLoader class. The implementation of this class is used for external asset loading and is discussed later in this chapter.

In this edition of the book, we show you how to use the getBytesLoaded() and getBytesTotal() methods in ActionScript to check the download progress of movie assets.

Cross-Reference 

You can find our coverage of Flash Player 3 and 4 movie preloaders (as discussed in the Flash 5 Bible [Wiley, 2001]) on the book's Web site, www.flashsupport.com/archive.




Macromedia Flash 8 Bible
Macromedia Flash8 Bible
ISBN: 0471746762
EAN: 2147483647
Year: 2006
Pages: 395

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net