質問

I need to load a sound file on my project but it must be loaded and called only once at the start of executing the code.One way to do this is using CSS but CSSis consuming high bit rate so how can i do this?

役に立ちましたか?

解決

I think you must read the AS3 doc: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Sound.html

As you can see you just have to create a new Sound object:

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

or if you want to wait for the load complete:

// 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 );
}

Hope this helps.

他のヒント

Firstly add sound in the library and name that mysound1 and see this code;

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

When your game complete put this code:-

mychannel.stop();
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top