topbanner_forum
  *

avatar image

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

Login with username, password and session length
  • Saturday December 14, 2024, 2:49 am
  • Proudly celebrating 15+ 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 11629 times)

RedPillow

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

Code: ActionScript [Select]
  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 PM by RedPillow »

Deozaan

  • Charter Member
  • Joined in 2006
  • ***
  • Points: 1
  • Posts: 9,778
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: [ActionScript 3] Play a sound when user clicks button?
« Reply #1 on: January 19, 2011, 01:26 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
    • Read more about this member.
    • Donate to Member
Re: [ActionScript 3] Play a sound when user clicks button?
« Reply #2 on: January 19, 2011, 01:34 PM »
You might be right ... someone said this:

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
  • ***
  • Points: 1
  • Posts: 9,778
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: [ActionScript 3/Adobe Flash] Play a sound when user clicks button?
« Reply #3 on: January 19, 2011, 01: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

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

Also this:

Code: ActionScript [Select]
  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)?:

Code: ActionScript [Select]
  1. function sound_play (e:MouseEvent):void {
  2. snd.play();
  3. }