Accessibility

ActionScript cookbook beta

Play an embedded sound

Problem Summary

You need to play a sound contained within your content and set its volume.

Solution Summary

Use the Sound, SoundChannel, and SoundTransform classes to play and manipulate sounds.

Explanation

ActionScript 2

function onSoundComplete():Void
{
   trace("sound is completed");
}

var my_sound:Sound = new Sound();

my_sound.attachSound("beep_id");
my_sound.setVolume(50);
my_sound.onSoundComplete = onSoundComplete;

my_sound.start();

ActionScript 3

function onSoundComplete(event:Event):void
{
   trace("sound is completed");
}

var my_sound:Sound = new beep_id();
var sTransform:SoundTransform = new SoundTransform();
sTransform.volume = .5;

var channel:SoundChannel = my_sound.play();
channel.soundTransform = sTransform;

channel.addEventListener(Event.SOUND_COMPLETE, onSoundComplete);