Hello Im creating a game , that have more than 200 sounds , so I cannot just put the sounds in my libray in flash and then instanciate them as class and play them. Because the sound it will play when I click one object is not always the same.
I have this function to play background sound , where enters the name of the song I wanna to be played :
public function startMusicBack(music:String):void{
var musicback:Sound = new Sound();
var bgChannel:SoundChannel;
var bgTransform:SoundTransform = new SoundTransform(1);
var req:URLRequest = new URLRequest(music);
try {
musicback.load(req);
//parar todos os sons
SoundMixer.stopAll();
// vou transformar o som para ele ficar mais baixo
bgTransform.volume = .05;
//faço o play do som mas meto num soun
bgChannel= musicback.play(0,999,bgTransform);
}
catch (err:Error) {
trace(err.message);
}
}
Ok this worked fine until I tryied do a export of the swf file , and then I got messages of error because of the path to the music is not correct .
Ok my question is , how can I embed the past with the sounds in the swf or how can I call musics in library of flash in runtime ???
You can embed sounds directly into your SWF using the Embed tag:
then you can create a new Sound as:
Although, with 200 sounds, this’ll probably make your SWF enormous and make your compile time a pain in the ass. For the problem that you’re having, it just looks like the path to your music file is wrong. If you had a project layout like this:
Then in your main class, you pass the path to the sound as relative to your *SWF* file (i.e. output.swf), so call your function like: