将声音文件加载为as3

问题描述 投票:0回答:2

我需要在我的项目中加载一个声音文件,但它必须在执行代码开始时加载和调用一次。一种方法是使用CSS但CSS消耗高比特率,那么我该怎么做呢?

actionscript-3 flex3
2个回答
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 );
}

希望这可以帮助。


0
投票

首先在库中添加声音并命名为mysound1并查看此代码;

var mysound:mysound1 = new mysound1 ();
var mychannel:SoundChannel = mysound1.play();

当你的游戏完成时把这段代码: -

mychannel.stop();
© www.soinside.com 2019 - 2024. All rights reserved.