Basic Flash ActionScript for Designers - Loading External MP3 Files
(Page 4 of 4 )
As far as audio files, Flash player supports only the MP3 file format. To load MP3 files at runtime, you need to use the loadSound() method of the Sound class. First, you need to create a Sound object, as shown in the following sample where "song1" is the instance of the sound object:
var song1:Sound = new Sound();
Then you need to use the loadSound() method of the sound object to load an event or a streaming sound. Event sounds are loaded completely before being played; streaming sounds play as they are downloaded. The isStreaming parameter of loadSound() can specify a sound as an event sound or a streaming sound.
After you load an event sound, you must call the start() method of the Sound class to make the sound play. Streaming sounds begin playing automatically, so you don't need start().
song1.loadSound("lastchristmas_wham.mp3", false);song1.start(); In the above sample, the first parameter is the mp3 file path and the send parameter is the isStreaming value, either true or false.
I recommended setting the isStreaming parameter to true, especially when you are loading large sound files so that the file starts playing as soon as possible.
To determine when a sound has completely downloaded, use the Sound.onLoad event handler. This event handler automatically receives a boolean value that indicates whether the file downloaded successfully.
song1.onLoad = function(success){
};
“Success” is the parameter which returns either true or false.
This article has covered most of the basics for adding interactivity to Flash movies for designers who don’t have any previous ActionScript knowledge. However there are a lot more features available for designers to learn, given enough ambition and patience.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |