Skip to main content
Participant
November 25, 2011
Question

How do I make it so that a sound is played when a button is pressed?

  • November 25, 2011
  • 1 reply
  • 490 views

I have a clickHandler event created for when the button is pressed, but I cannot figure out how to make it so that it plays a sound when pressed. i have the sound in my assets folder. What is the command for that function? Also, can I make the button so that it is transparent, like, so that it looks like the user is pressing in a part of an image in the background?

This topic has been closed for replies.

1 reply

The_Preacher1
Inspiring
November 25, 2011

I would recommend that you do something like this:

// create a SoundChannel variable

var channel:SoundChannel;

// in the library set the AS linkage for your mp3 file to myMP3sound (or change this to match yours)

var myMP3sound:Sound = new WhatSayHorse_mp3();

// play the sound using a call like this based on when your button is pressed in your click handler code:

channel = myMP3sound.play();

// OPTIONAL

// add an event listener to call a function when the sound has completed

channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);

// Add the fuction and put whatever code in it that you need.

function onPlaybackComplete(evt:Event):void {

       // add the code here that you want executed on sound finished playing.

}

//---------------------------------------

//  I hope this helps!

//  Grace & Peace to you!

//  jim

//------------------------------------