2013-10-18 116 views
0

我需要在我的项目中加载声音文件,但它必须在执行代码的开始时被加载和调用一次。一种方法是使用CSS,但CSS使用高比特率,所以如何我可以这样做吗?加载声音文件as3

+0

id想要了解如何使用css加载声音,请分享您的代码 – 2013-10-18 18:33:43

回答

0

我认为你必须阅读AS3 DOC:http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Sound.html

正如你所看到的,你只需要创建一个新的Sound对象:

var mySound:Sound = new Sound(new URLRequest('http://url.to.your.sound')); 

,或者如果你想等待负载完成:

// create sound object 
var mySound:Sound = new Sound(); 
// listen for the end of the loading 
mySound.addEventListener(Event.COMPLETE, _onSoundLoaded); 
// maybe you want to track the progress of the loading 
mySound.addEventListener(Event.COMPLETE, _onSoundLoading); 
// start loading 
mySound.load(new URLRequest('http://url.to.your.sound')); 

// the loading is complete 
function _onSoundLoaded(e:Event):void 
{ 
    // play the sound 
    mySound.play(); 
} 

// the loading progress 
function _onSoundLoading(e:Event):void 
{ 
    // trace the progression 
    trace(mySound.bytesTotal/mySound.bytesLoaded); 
} 

希望这会有所帮助。