Ok, I have noticed so many quesitons regarding audio on the forums. Time to give something back. I am going to give a brief tutorial on how I **dynamicaly load sound ** into my flash movie.
First let me start by saying that I prefer to load sound externally. Meaning the sound [COLOR=red]is not[/COLOR] in your .fla file. Instead it is in the same folder as your .swf. In case the reason isn’t obvious, this let’s us stream large sound files, that won’t kill our .swf in file size. Another great feature is we can stream the sound. Meaning the sound will play while it’s being downloaded. Okay let’s start.
Syntax for dynamically loading a sound object:
[AS]
x.loadSound(“url”, isStreaming);
[/AS]
Syntax for the sound object method loadSound:
[AS]
x.loadSound(“na.mp3”, true); // true because we want our mp3 to stream
[/AS]
The following is a common way to define the sound object with the loadSound method:
[AS]
x = new Sound(x);
x.loadSound(“na.mp3”,true);
[/AS]
[COLOR=red]Create an example:[/COLOR]
Let’s start a new document. Create 2 layers in your timeline. Layer 1 will be “actions” and we will use layer 2 for our buttons (“buttons”). Let’s declare our sound object on layer 1.
[AS]x = new Sound(x);[/AS]
That’s it for layer 1.
Now on layer 2 create 2 buttons. On/Off. Give the On buttons these actions:
[AS]
on(release){
x.loadSound(“na.mp3”,true);
x.start(0,999);
}
[/AS]
The Off button simply get’s the following actions
[AS]
x.stop();
[/AS]