PDA

View Full Version : [AS3] Play sound on click of a button


v_gyku
09-11-2006, 07:18 AM
I want to play a sound on click of a button. I can do this in AS 2.0

//Action Script 2.0

snd=new Sound();
snd.attachSound("try");
snd.start();


//Action Script 3.0

var snd:Sound = new Sound();
//what will come here, as .attachSound() is not there in AS 3.0
snd.play();


Thanks...

v_gyku
09-11-2006, 11:11 AM
This works:


var snd:Sound = new Sound();
snd.load(new URLRequest("my.mp3"));
snd.play();

pfzngn
07-21-2007, 04:33 PM
This works:


var snd:Sound = new Sound();
snd.load(new URLRequest("my.mp3"));
snd.play();


Is there a way to attach the sound file to a variable without having to load it externally? I'd rather not have my sound file floating around outside the swf, especially if i'm going to be using it quite often.

tullstedt
01-17-2008, 09:23 AM
Is there a way to attach the sound file to a variable without having to load it externally? I'd rather not have my sound file floating around outside the swf, especially if i'm going to be using it quite often.

This might be an ugly solution, but aint it possible to place the sound on the first frame of a movieclip and play that mc on each click?

zworp
01-17-2008, 09:28 AM
sound works just as movieclips, create a sound in the .fla, use the linkage dialog in teh library and set Class to: "MySound1"
then use it with:

var snd:MySound1= new MySound1();
snd.play();

should work..

DesignerScott
02-12-2008, 01:06 AM
While scouring as3 forums lately there's something I've been noticing people don't understand:
Not everyone is compiling from Flash.
So just keep that in mind while you all try to be helpful.
P.S. sorry I can't help, I'm looking for the answer too. As well as some way to work with opentype fonts using code instead of linkage ;)