我需要在我的项目中加载声音文件,但必须在执行代码开始时加载并调用一次。一种方法是使用CSS但CSS消耗高比特率所以我该怎么做呢?
答案 0 :(得分:0)
我认为您必须阅读AS3文档: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 );
}
希望这有帮助。
答案 1 :(得分:0)
首先在库中添加声音,并将其命名为mysound1并查看此代码;
var mysound:mysound1 = new mysound1 ();
var mychannel:SoundChannel = mysound1.play();
游戏完成后,输入以下代码:-
mychannel.stop();