Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • September 04, 2015, 01:49:50 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

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

RedPillow

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

Code: ActionScript
  1. var snd:MySound1= new MySound1();
  2.  
  3. soundbutton_MC.addEventListener (MouseEvent.CLICK, soundbutton_Handler);
  4.  
  5. function soundbutton_Handler (e:MouseEvent):void {
  6. snd.play();
  7. }
  8.  

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, 01:47:54 PM by RedPillow »

Deozaan

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 7,050
    • View Profile
    • Just for mouser.
    • Donate to Member
Re: [ActionScript 3] Play a sound when user clicks button?
« Reply #1 on: January 19, 2011, 01:26:22 PM »
I don't know for sure, but it looks like the sound file might be defined in the MySound1 class.


RedPillow

  • Member
  • Joined in 2008
  • **
  • Posts: 141
  • Pillows.
    • View Profile
    • Donate to Member
Re: [ActionScript 3] Play a sound when user clicks button?
« Reply #2 on: January 19, 2011, 01:34:46 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: 7,050
    • View Profile
    • Just for mouser.
    • Donate to Member
Re: [ActionScript 3/Adobe Flash] Play a sound when user clicks button?
« Reply #3 on: January 19, 2011, 01:55:18 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

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

http://img407.imageshack.us/img407/1435/aflashlink.jpg
[ActionScript 3/Adobe Flash] Play a sound when user clicks button?


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

- RedPillow

RedPillow

  • Member
  • Joined in 2008
  • **
  • Posts: 141
  • Pillows.
    • View Profile
    • Donate to Member
Re: [ActionScript 3/Adobe Flash] Play a sound when user clicks button?
« Reply #5 on: January 19, 2011, 02:23:11 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
  1.  
  2. var bgMusic:bgMsc= new bgMsc();
  3. bgMusic.stop();
  4.  

Also this:

Code: ActionScript
  1.  
  2. var bgMusic:bgMsc= new bgMsc();
  3. bgMsc.stop();
  4.  

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
  1. function sound_play (e:MouseEvent):void {
  2. snd.play();
  3. }
  4.