Accessibility

ActionScript cookbook beta

Dynamically load and play a sound

Problem Summary

You need to dynamically load and play an MP3 file.

Solution Summary

Use the Sound.load API to load and control the sound.

Explanation

ActionScript 2

var sound = new Sound();
sound.loadSound("sound.mp3", true);

ActionScript 3

var url = new URLRequest("sound.mp3");
var sound = new Sound();
sound.load(url);
sound.play();