Skip to main content
Inspiring
January 16, 2017
Answered

Play audio onClick

  • January 16, 2017
  • 2 replies
  • 1724 views

Hi,

I've been trying to get some music to play when the user clicks (its for a mute and unmute button)

I've got the mute button to work with the stop all sounds code snippet. I tried to adapt it and this is what I have:

//unmute sound

instVolOn.addEventListener(MouseEvent.CLICK, Unmute);

function Unmute(event:MouseEvent):void

{

  SoundMixer.Playl(welcomeMusic.mp3);

}

Safe to say it didn't work, can someone help?

Thanks,
Jack

This topic has been closed for replies.
Correct answer robdillon

It's difficult to tell exactly what you are attempting from your code. If you have created a sound object and attached a sound file from your movie's Library to that sound object then you should play and pause or stop that sound through the sound object. If your sound is embedded into a layer on your timeline then you can stop the sound through the SoundMixer object but you can't play it. The sound is playing wild on the timeline and once it's stopped it stays stopped.

Here's an Adobe help file that explains working with sounds in detail: http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7d21.html

2 replies

robdillon
robdillonCorrect answer
Participating Frequently
January 16, 2017

It's difficult to tell exactly what you are attempting from your code. If you have created a sound object and attached a sound file from your movie's Library to that sound object then you should play and pause or stop that sound through the sound object. If your sound is embedded into a layer on your timeline then you can stop the sound through the SoundMixer object but you can't play it. The sound is playing wild on the timeline and once it's stopped it stays stopped.

Here's an Adobe help file that explains working with sounds in detail: http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7d21.html

Inspiring
January 16, 2017

Hirobdillon​​,

I think you're right - as I'm new to this I didn't know having the sound as a layer couldn't be played once stopped. I've had a look at the article and I think that's going to be my best answer.

Thanks Q4T​ for the suggestions too!:)

Thanks,
Jack

Legend
January 17, 2017

You can restart sounds fine using a two-frame movieclip. Sound in first frame as Start or Event, then a keyframe and a stop statement in the second frame. To restart the sound just tell the clip to play again.

Jon Chambers
Inspiring
January 16, 2017

I don't think "Playl" is a real word. I tried googling "SoundMixer.Playl", and this forum post was the only result I could find.

Perhaps delete the "l"?

Inspiring
January 16, 2017

After I posted I noticed the l and removed it from my code and it still didn't work - thought it was a rookie mistake!

Thanks,
Jack

Jon Chambers
Inspiring
January 16, 2017

try "play" with lowercase "p"