Wednesday, May 9, 2007

Pre-loading sound within a flash animation

if you want to display a preloader, load the sound in combination with onEnterFrame. Something like


Sound mySound = new Sound();
mySound.loadSound("my.mp3", true); //stream it
onEnterFrame = function()
bTotal = mySound.getBytesTotal();
bLoaded = getBytesLoaded();
if (bLoaded >= bTotal)
delete onEnterFrame;
// do the animation here, based on the percentage represented by bLoaded


Flash Player 6.

mySound.loadSound(" url ", isStreaming )

url - The location on a server of an MP3 sound file.
isStreaming - A Boolean value that indicates whether the sound is a streaming or event sound.



Method; loads an MP3 file into an instance of the Sound object. You can use the isSteaming parameter to indicate whether the sound is an event or a streaming sound.

Event sounds are completely loaded before they play. They are managed by the ActionScript Sound object and respond to all methods and properties of this object.

Streaming sounds play while they are downloading. Playback begins when sufficient data has been received to start the decompressor.

All MP3s (event or streaming) loaded with the Sound.loadSound method are saved in the browser's file cache on the user's system.

The following example loads an event sound:

s.loadSound( "http://serverpath:port/mp3filename", false);

The following example loads a streaming sound:

s.loadSound( "http://serverpath:port/mp3filename", true);

No comments: