DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: [ActionScript 3/Adobe Flash] Play a sound when user clicks button?  (Read 13,928 times)

RedPillow

  • Pillows.
  • Member
  • Joined in 2008
  • **
  • Posts: 141
I found something like this:

Code: (actionscript)
var snd:MySound1= new MySound1();

soundbutton_MC.addEventListener (MouseEvent.CLICK, soundbutton_Handler);

function soundbutton_Handler (e:MouseEvent):void {
snd.play(); 
}

I have the sound-effect in my Adobe Flash's library ... where should I put it and how to make the script know to play that one?
« Last Edit: January 19, 2011, 07:47 PM by RedPillow »

Deozaan

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 9,827
    • Participated in NANY Challenge Eight Times
    • Cody Award
Re: [ActionScript 3] Play a sound when user clicks button?
« Reply #1 on: January 19, 2011, 07:26 PM »
I don't know for sure, but it looks like the sound file might be defined in the MySound1 class.

RedPillow

  • Pillows.
  • Member
  • Joined in 2008
  • **
  • Posts: 141
Re: [ActionScript 3] Play a sound when user clicks button?
« Reply #2 on: January 19, 2011, 07:34 PM »
You might be right ... someone said this:

Quote
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..


But since Im new with flash I have no idea how to "create a sound in the .fla, use the linkage dialog in teh library and set Class to: "MySound1"".
(Incase it's important ... Im making a basic starting-sequence for a flash-game/animation like "Game by: blahahah" and there's a button which links to my twitter but I want it to make *click* -sound when clicked)

Deozaan

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 9,827
    • Participated in NANY Challenge Eight Times
    • Cody Award
Re: [ActionScript 3/Adobe Flash] Play a sound when user clicks button?
« Reply #3 on: January 19, 2011, 07:55 PM »
It's been a few years since I used Flash, but I think you can import a sound file to your library from the File -> Import menu. As for linkage, right click the file in your library and look for a "linkage" option. It may be in the "Properties" menu.

For more specific help, I suggest you check the help file since I'm sure it would cover importing sound files and library linkage.

RedPillow

  • Pillows.
  • Member
  • Joined in 2008
  • **
  • Posts: 141
Re: [ActionScript 3/Adobe Flash] Play a sound when user clicks button?
« Reply #4 on: January 19, 2011, 08:08 PM »
Aha!
It was hidden under Advanced > Something > Something :P



Got it to work just right - Thanks so much for help!

- RedPillow

RedPillow

  • Pillows.
  • Member
  • Joined in 2008
  • **
  • Posts: 141
Re: [ActionScript 3/Adobe Flash] Play a sound when user clicks button?
« Reply #5 on: January 19, 2011, 08:23 PM »
Oh ... I also have background-music playing from the start ... I'd like it to stop when I say so.

Tried this one:

Code: (actionscript)

var bgMusic:bgMsc= new bgMsc();
bgMusic.stop();

Also this:

Code: (actionscript)

var bgMusic:bgMsc= new bgMsc();
bgMsc.stop();

Error is this:

TypeError: Error #1006: stop is not a function.
at Untitled_fla::MainTimeline/frame96()


Isn't this similar (this is playsound-function when someone click the twitter-button)?:

Code: (actionscript)
function sound_play (e:MouseEvent):void {
snd.play();
}

Original address: https://www.donationcoder.com/forum/index.php?topic=25338.0