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

Tags: , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: