Welcome Guest.   Make a donation to an author on the site September 20, 2014, 06:58:25 AM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
The N.A.N.Y. Challenge 2011! Download 30+ custom programs!
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: [ActionScript 3/Adobe Flash] Play a sound when user clicks button?  (Read 4580 times)
RedPillow
Member
**
Posts: 140


Pillows.

see users location on a map View Profile Read user's biography. Give some DonationCredits to this forum member
« on: January 19, 2011, 01:22:36 PM »

I found something like this:

Formatted for ActionScript with the GeSHI Syntax Highlighter [copy or print]
  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. }

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 » Logged
Deozaan
Charter Member
***
Posts: 6,347



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« 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.
Logged

RedPillow
Member
**
Posts: 140


Pillows.

see users location on a map View Profile Read user's biography. Give some DonationCredits to this forum member
« 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)
Logged
Deozaan
Charter Member
***
Posts: 6,347



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« 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.
Logged

RedPillow
Member
**
Posts: 140


Pillows.

see users location on a map View Profile Read user's biography. Give some DonationCredits to this forum member
« Reply #4 on: January 19, 2011, 02:08:15 PM »

Aha!
It was hidden under Advanced > Something > Something tongue



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

- RedPillow
Logged
RedPillow
Member
**
Posts: 140


Pillows.

see users location on a map View Profile Read user's biography. Give some DonationCredits to this forum member
« 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:

Formatted for ActionScript with the GeSHI Syntax Highlighter [copy or print]
  1. var bgMusic:bgMsc= new bgMsc();
  2. bgMusic.stop();

Also this:

Formatted for ActionScript with the GeSHI Syntax Highlighter [copy or print]
  1. var bgMusic:bgMsc= new bgMsc();
  2. 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)?:

Formatted for ActionScript with the GeSHI Syntax Highlighter [copy or print]
  1. function sound_play (e:MouseEvent):void {
  2. snd.play();
  3. }

Logged
Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.077s | Server load: 0.15 ]