Using _framesloaded and _totalframes


Beginning with Flash 3, you could use an action called ifFrameLoaded to check whether a particular labeled frame or frame number had loaded. That action carried over to Flash 4, and you still can use it in Flash 5. It is now considered a deprecated action, so it most likely will not be supported in future versions of Flash. A better choice is to use the _framesloaded and _totalframes properties that were introduced in Flash 4 and that have not been deprecated:

  • _framesloaded. Reads the number of frames that have loaded from a streaming movie.

  • _totalframes. The total number of frames in the movie.

You can use these two properties to do a little math, which comes in very handy. If you divide the _framesloaded by the _totalframes, you get a number between 0 and 1. When the number reaches 1, all the frames have loaded. Don't believe me? Say you had a movie clip that has 100 frames. You can set up your calculation inside an onClipEvent(enterFrame) so that it continuously processes, and you get the results in Table 16.1.

Table 16.1. Calculating the Percentage of Frames Loaded Using the _framesloaded and _totalframes Properties

_framesloaded

_totalframes

_framesloaded/_totalframes

20

100

.20

35

100

.35

60

100

.60

100

100

1

Do you have to wait until the entire movie clip has downloaded before starting playback? Of course not. You could start playback as soon as the movie clip reached a certain frame or after a certain percentage of the frames have loaded. It all depends on what you need to get the best playback from your movie, and clearly it will vary from project to project. One way you could use this ”and you actually saw this in action in the Transit film in Chapter 11, "Faking Video in Flash" ”would be to set up a multilevel loading sequence. In the case of the Transit film, you had two separate loading sequences. Each sequence acted as a preloader for the following sequence. In this case, you waited for a specific frame to load before you proceeded with the movie.

Okay, these properties are useful up to a point, but you can't get at the true percentage of the movie that's loaded because different frames have different amounts of content. If you want to be able to accurately account for how much of the movie has downloaded, you're going to need to use two methods of the Movie Clip object: getBytesLoaded() and getBytesTotal().



Inside Flash
Inside Flash MX (2nd Edition) (Inside (New Riders))
ISBN: 0735712549
EAN: 2147483647
Year: 2005
Pages: 257
Authors: Jody Keating

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