Sunday, 5 June 2011

External wav files in Actionscript 3

In Actionscript 3 you can only play wav files that are imported into the Flash library you can’t play external wav files. This is because when wav files are in the library they get converted in Sound objects which give support for playing the wav file format. The external wav format is not natively supported in the Sound Class.

However, there is a class called: as3wavsound which can be downloaded here. The as3wavsound class has essentially the exact same API as the native Sound class apart from the ability to play wav files. This makes it simple and easy to use, here is an example.

var loader:URLLoader = new URLLoader();
loader.dataFormat = 'binary';
loader.addEventListener(Event.COMPLETE, completeHandler);
loader.load(new URLRequest("[yourwavfile].wav"));

function completeHandler(e:Event):void{
 var sound:WavSound = new WavSound( as ByteArray);;


  COPYRIGHT © 2014 · ILIKE2FLASH · Theme by Ourblogtemplates

Back to TOP