User Guide
Preloading external media 303
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("http://yourserver.com/songs/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.bytesLoaded and
NetStream.bytesTotal properties. Try loading your song from a server to see the loading
progress in the Output panel.
Another way to preload FLV files is to use the
NetStream.setBufferTime() method. This
method takes a single parameter that indicates the number of seconds of the FLV stream to
download before playback begins.
For more information, see
MovieClip.getBytesLoaded(), MovieClip.getBytesTotal(),
NetStream.bytesLoaded, NetStream.bytesTotal, NetStream.setBufferTime(),
setInterval(), Sound.getBytesLoaded(), and Sound.getBytesTotal() in Flash ActionScript
Language Reference.