This program loads an mp3 file and plays it. The entire program is given below and the compiled SWF is shown above. To hear the file play, left-click the window above.
The code begins with three lines that tell the user to click the screen. Then we create a String for the URL, which could also be a local file. Next, we set our function as the callback for mouse clicks. Inside the function OnClick(), we create a Sound object, load the sound file, and then play it.
// Output the initial instructions to user
var qInstructions:TextField = new TextField();
qInstructions.text = "Click To Play";
addChild(qInstructions);
const ksXoaXDotNet:String = "http://www.xoax.net/public/XoaXDotNet.mp3";
// Play the mp3 when the screen is clicked
stage.addEventListener(MouseEvent.CLICK, OnClick);
function OnClick(e:MouseEvent): void {
var qSound:Sound = new Sound();
qSound.load(new URLRequest(ksXoaXDotNet));
qSound.play();
}
Tags: 3.0, actionscript, adobe, code, example, file, flash, mp3, play, program, programming, sound, swf
Michael HallBy: Michael Hall

RSS
Atom
Feedburner
I tried this code and I keep getting SecurityError: Error #2000: No active security context.