MACROMEDIA FLASH MX 2004 - ACTIONSCRIPT Reference Manual page 201

Actionscript reference guide
Hide thumbs Also See for FLASH MX 2004 - ACTIONSCRIPT:
Table of Contents

Advertisement

Preloading MP3 and FLV files
To preload MP3 and FLV files, you can use the
mechanism that checks the bytes loaded for a Sound or NetStream object at predetermined
intervals. To track the download progress of MP3 files, use the
Sound.getBytesTotal()
NetStream.bytesLoaded
The following code uses
object at predetermined intervals.
// Create a new Sound object to play the sound.
var songTrack = new Sound();
// Create the polling function that tracks download progress.
// This is the function that is "polled." It checks
// the download progress of the Sound object passed as a reference.
checkProgress = function (soundObj) {
var bytesLoaded = soundObj.getBytesLoaded();
var bytesTotal = soundObj.getBytesTotal();
var percentLoaded = Math.floor(bytesLoaded/bytesTotal * 100);
trace("%" + percentLoaded + " loaded.");
}
// When the file has finished loading, clear the interval polling.
songTrack.onLoad = function () {
clearInterval(poll);
}
// Load streaming MP3 file and start calling checkProgress()
songTrack.loadSound("beethoven.mp3", true);
var poll = setInterval(checkProgress, 1000, songTrack);
You can use this same kind of polling technique to preload external FLV files. To get the total
bytes and current number of bytes loaded for an FLV file, use the
NetStream.bytesTotal
Another way to preload FLV files is to use the
method takes a single parameter that indicates the number of seconds of the FLV stream to
download before playback begins.
For more information, see
NetStream.bytesLoaded
setInterval()
"ActionScript Dictionary," on page
methods; to track the download progress of FLV files, use the
and
NetStream.bytesTotal
setInterval()
properties.
MovieClip.getBytesLoaded()
,
NetStream.bytesTotal
,
Sound.getBytesLoaded()
205.
setInterval()
Sound.getBytesLoaded()
properties.
to check the bytes loaded for a Sound or NetStream
NetStream.setBufferTime()
,
MovieClip.getBytesTotal()
,
NetStream.setBufferTime()
, and
Sound.getBytesTotal()
function to create a "polling"
NetStream.bytesLoaded
method. This
,
in
Chapter 12,
Preloading external media
and
and
,
201

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH MX 2004 - ACTIONSCRIPT and is the answer not in the manual?

Table of Contents