hello im creating game , have more 200 sounds , cannot put sounds in libray in flash , instanciate them class , play them. because sound play when click 1 object not same.
i have function play background sound , enters name of song wanna 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 som mas meto num soun bgchannel= musicback.play(0,999,bgtransform); } catch (err:error) { trace(err.message); }
}
ok worked fine until tryied export of swf file , , got messages of error because of path music not correct .
ok question , how can embed past sounds in swf or how can call musics in library of flash in runtime ???
you can embed sounds directly swf using embed tag:
// path here relative *file*, not swf [embed(source = "../../../../../assets/somesound.mp3", mimetype = "audio/mpeg")] public var mysound:class;
then can create new sound as:
var s:sound = new mysound;
although, 200 sounds, this'll make swf enormous , make compile time pain in ass. problem you're having, looks path music file wrong. if had project layout this:
parentfolder - assets - mysound.mp3 - bin - output.swf - src - subfolder - main.as
then in main class, pass path sound relative *swf* file (i.e. output.swf), call function like:
this.startmusicback( "../mysound.mp3" );
Comments
Post a Comment