Tag Archive | sound

Playing with sound in Action Script 3 (Flash)

To play an external audio files:

var hisPromise:Sound = new Sound();
var hisPromiseChannel:SoundChannel = new SoundChannel();
hisPromise.load(new URLRequest("audio/01_His_Promise_is_Forever.mp3"));
hisPromiseChannel = hisPromise.play();

to stop:

hisPromiseChannel.stop();

to adjust volume (range 0 – 1):

hisPromiseChannel.soundTransform = new SoundTransform(0.2);

to Pause:

lastPosition = myChannel.position;
myChannel.stop();

to Play from last position:

myChannel = mySound.play(lastPosition);

to Loop sound:

var hisPromise:Sound = new Sound();
var hisPromiseChannel:SoundChannel = new SoundChannel();
hisPromise.load(new URLRequest("audio/01_His_Promise_is_Forever.mp3"));
playSound();
function playSound():void
{
hisPromiseChannel = hisPromise.play();
hisPromiseChannel.addEventListener(Event.SOUND_COMPLETE, onComplete);
}
function onComplete(event:Event):void {
SoundChannel(event.target).removeEventListener(event.type, onComplete);
playSound();
}