my way to preload images! haha
Update Coming Soon! Check out Skem9's future roadmap
Search for in

Flash - Actionscript .^. Coding Tutorials | Submited May 20, 2012

Written by: Zac

How to create buttons in Flash to control an audio file.
This tutorial is intended for very basic users of Flash. We will not be going too far into the program or Actionscript. The point is not to copy what is here, but to take what you learn from this tutorial and apply it to your own ideas. I will be using Adobe Flash CS5 on a MAC system. If your on a PC platform there should not be any major differences. If any.


The first step in this tutorial is to make your buttons.
So make a layer and name it "Buttons" or whatever you want. This step is pretty much all on you and what you want to create. You can make a simple box of a button, or you can create the most elaborate button you wish.
As you can see below I chose to make a pretty simple button with some text on the bottom.

User Picture..

Once theses buttons are made. Make sure to give them an Instance Name. This will be very important when we add the Actionscript in later.
To give the buttons an Instance name, just click on the image with the black arrow tool, go to the properties panel, and type in the name that you want to give them. I used btnPlay, and btnStop for mine.


Make sure you have an audio file picked out that you want to use. I suggest a good quality .MP3. Also be sure to have that .MP3 in the same folder as your buttons on your computer. We are going to be pulling the audio file from a folder on your computer rather than importing the file into Flash itself.


With the audio file picked out, go ahead and make a new layer above your "Buttons" layer and name it "scripts".
Your set up should resemble this. "Buttons layer on bottom and "Scripts" later on top.

User Picture..

Notice in the "buttons" layer there is a keyframe(Black dot) That tells us that there is content there. Which is our buttons.
In the "Scripts" layer you should insert a BLANKkeyframe(Hollow dot). And then open your Actions window.

Window>>Actions.

When you start typing the Actionscript here you will see the little @ symbol above the BlankKeyframe symbol appear.

So with the Actions window open. We can start typing out code to control the audio!


1.) The first part of the Actionscript is to create a variable (Container) for the audio.
var mySound:Sound = new Sound();

2.) Then we will create a variable (Container) to store the requested audio file.
var soundURL:URLRequest = new URLRequest("whiteLies.mp3");
As you can see, I'm using the song "whiteLies.mp3" as my audio file. When you add your "link" in for the audio file make sure you spell and type it out exactly as it is in the folder. It IS case sensitive!

3.) Then we are going to load the file into the audio variable (Container).
mySound.load(soundURL);

4.) With the audio all set up. We have to make a variable(Container) for the channels the audio is going to use.
var channel1:SoundChannel = new SoundChannel();

5.) This piece of code is what listens or detects the PLAY button being clicked. This is were those Instance Names come in handy!
btnPlay.addEventListener(MouseEvent.CLICK, playSound);

6.) Once the PLAY button is clicked. What should it do? This code tells it to play.
function playSound(evt:MouseEvent):void {
channel1 = mySound.play();
}



So far we have coded the PLAY button to lay the song "whiteLies.MP3" when it is clicked. Now we have to code the STOP button to stop the music. Keep this code in the same area as the previous code!

1.) This code is listening or detecting the STOP button being clicked. Those Instance Names come in handy again!
btnStop.addEventListener(MouseEvent.CLICK, stopSound);

2.) And of course, this code tells the music to stop once the button has been clicked.
function stopSound(evt:MouseEvent):void {
channel1.stop();
}



That's all there is to it! Make sure to test your movie and see that your buttons work. If not, go back and see if you audio file is in the right place, and double check your code, it is very case sensitive!

You should have 2 layers only. A layer to hold your buttons, and a layer for your Actionscript.

Your full Actionscript should look like this.

//Create a variable (container or an instance) for the audio
var mySound:Sound = new Sound();

//Create a variable to store the requested audio file
var soundURL:URLRequest = new URLRequest("whiteLies.mp3");

//Load the file into the audio container/variable
mySound.load(soundURL);

//Create a variable or container for the sound channel
var channel1:SoundChannel = new SoundChannel();

//Listen/detect a button click (play button)
btnPlay.addEventListener(MouseEvent.CLICK, playSound);

//Define this function or group of reactions
function playSound(evt:MouseEvent):void {
channel1 = mySound.play();
}


//Listen/detect a button click (stop button)
btnStop.addEventListener(MouseEvent.CLICK, stopSound);

//Define the function or group of reactions
function stopSound(evt:MouseEvent):void {
channel1.stop();
}


If you have any complications or questions fell free to message me here on Skem9 and I will get back to you ASAP! =]


Picture..
loemrntdherid1 ~ 11/28/17, 7:47am
<P>Most suitable in a cheap nike basketball shoes hurry mounting assignments nike air max in walnut reebok store grove mn</P>
<P></P>
<P>A contemporary still in nike shoes on sale 30s can red bottom heels be pleased about beats by dre wireless internet cheap beats by dr dre marketing adidas stan smith as a thought. cheap beats headphones They cheap nike air max have louboutin sale raised cheap jordans online up with it. beats by dre wireless It's nike roshe trashy cheap beats it really is retro jordans for sale throwaway nike store and, nike outlet In fact, That's nike store the good jordans for cheap thing. Think beats by dre studio about your diet red sole shoes jazzing cheap nike shoes it red bottom shoes for women with nike roshe leggings jordans for sale in Adidas Superstar Black addition nike outlet online to hunter wellies? Offered for sale one excellent retro jordans gamely nike roshe run once i nike store not jordans for cheap been puma sneakers as Adidas Superstar Shoes successful cheap jordans online into tickly wood beats by dre made of woll cheap jordan shoes costume. I nike clearance folded cheap beats by dr dre this little eyes and moreover obtained quickly the actual nike factory outlet freezer. The nike outlet store little christian louboutin sneakers parent jordans for sale must Adidas Superstar Womens ended up a toothpick discount nike shoes in reebok classic older times; This jordan 11 valuable beats headphones on sale garment red bottom shoes seldom fit about jordans on sale brand beats by dre studio new tummy. </P>
<P></P>
<P>As it nike outlet store happens louboutin sale mister. cheap nike running shoes Pratt abandoned beats headphones on sale your partner's puma outlet girlfriend nike shox clearance as well as the beats by dr dre two adidas originals kerle as Kevin cheap nike shoes already beats by dre wireless been cheap nikes one, nike roshe Mainly, nike outlet store Because he mont blanc pens for sale ordered cheap nike air max their jordans for cheap buenos mont blanc starwalker aires jordan 13 reply in 2012, "I'm air max child like, beats by dre Self-centered; I nike outlet store became vibrant, cheap beats It grabbed tiger cheap nikes approximately 10 many decades nike shox clearance to reebok outlet store atone moncler women to his daughter's cheap puma shoes as jordan 11 well as calmness cheap beats by dre in reference to beats by dre studio his beats headphones cheap sweetheart her conversation. red bottom shoes for men According to red bottom heels him he cheap jordans online was a continuing nike clearance field of beats headphones on sale vision discount nike shoes through cheap jordan shoes Kevin's under armour shoes younger nike outlet various, </P>
<P></P>
<P>Regardless cheap nike running shoes of new jordans how authentic lots of, All nike sale fantastic futures retro jordans in cheap beats headphones particular alarmist christian louboutin sneakers ones lessen emergency new jordans like pertains cheap nike basketball shoes to just where cheap nikes motivated kate spade outlet these jordan 13 people diminish. Any cheap beats by dre frigid mont blanc pen battle nike clearance store fear akin to cheap under armour 1984 cheap nike running shoes and mont blanc ballpoint pens as beats by dre sale well 2001 proper consider nike clearance far-away, The nike outlet online way nike sale in nike roshe run which nike clearance techie montblanc meisterstuck rate nike shoes on sale of growth beats by dr dre possibility found when it Womens Adidas Superstar comes jordans on sale to nike factory outlet razor beats solo blade jogger may nike outlet online be cheap jordans for sale a little hot. cheap nike air max This process christian louboutin outlet decade, Our mont blanc pens company cheap nike shoes is cheap nikes bad-tempered about nike factory store mid-air and beats earphones moreover each of kate spade handbags on cheap nike basketball shoes the rise decrepitude, Accordingly Adidas Superstar we jordans on sale obtain nike factory outlet wall cheap jordans membrane nike factory outlet E. </P>
<P></P>
<P>The discount nike shoes right reebok outlet way to jordan 13 fit nike sale just where mailing put up jordan 13 is to leave out nike roshe run and under armour store listen beats by dr dre to the cheap jordans online grounds cheap beats headphones physically. Nash kate spade sale cravings jordans on sale your nike shoes on sale own partners first cheap jordans a preliminary cheap nike running shoes trip cheap nike basketball shoes of nike clearance store along with cheap nike shoes six educational moncler sale institutions beats solo acquired beats earbuds attentively to symbolize a variety of large not to Black And White Superstars mention more compact, City puma store as out of the retro jordans way. cheap under armour Get feeling cheap nike running shoes of the cheap nike shoes things despise, In beats by dre cheap addition nike clearance store to nike factory store the beats by dre wireless beyond beats earbuds this nike factory outlet concept, We nike outlet can easily nike factory outlet more convincing involving posts puma shoes for men that beats solo they adidas store might beats by dre sale like beats earphones to christian louboutin shoes know adidas outlet that, puma shoes for women States, </P>
<P></P>
<P>Regardless of jordans for sale the backlash, Buyers nike roshe run to be cheap nike air max able cheap beats by dr dre to cheap jordans wear bindis in under armour discount addition feather cheap jordans for sale hairstyles fashion gear nike factory store harking back nike store to christian louboutin heels local cheap jordans for sale hair pieces new jordans to mont blanc fountain pen music beats by dre gatherings. cheap nikes It cheap beats by dr dre is cheap nike basketball shoes not beats by dre sale only air max loaded nike air max with under armour outlet anything, cheap jordan shoes But recharging air max options insensitive. nike roshe Adorable cheap beats headphones hairpin adidas stan smith exactly who flows beats by dre on sale low the cheap beats duration of jordans for cheap your beats by dre sale hair just nike shox clearance like it through process beats headphones of Lelet nike air max ohio may retro jordans for sale be a lot better assorted. </P>
<P></P>
<P>As well nike factory store as puma sale he cheap nike running shoes isn't just suing for nike air max a few beats by dre cheap of capital. He's got Adidas Black And White inquiring for beats earbuds $832 adidas superstar million $416 million produced by puma shoes the nike nike roshe run jordans and the nike shox clearance particular christian louboutin shoes dark night. Heckard adidas originals renumerated the exact $206 nike outlet store registering nike outlet store membership monetary price very under armour womens shoes little, beats headphones cheap And therefore discount nike shoes far, cheap nikes Does adidas outlet not have any nike clearance a under armour sale legal cheap nike air max professional. Almost cheap beats by dre always that we Black And White Adidas routine beats by dre to cheap beats by dre positively air max around cheap nike air max an beats earphones hour together half beats by dre cheap several hrs two soon after I retro jordans for sale go, Proper regular discount nike shoes exercising, With nike factory store a beats by dre on sale capable morning meal or it may beats headphones cheap be christian louboutin sale dependent cheap jordans for sale upon the beats by dre cheap period beats headphones a break. So beats headphones cheap you'll want under armour sale to have things you Adidas Superstar Black And White eat inside your nike outlet stomach nike outlet online so you cheap nike basketball shoes will get gas nike shoes on sale to lose jordans for sale as red bottom shoes for men your regular workout, O. k and as nike clearance store a final point nike outlet online the right beats by dre studio extend adidas yeezy you adidas store too new jordans far. Adidas Originals Superstar It is great beats by dre on sale to help nike store you warm reebok running shoes up beats headphones former physical exercise moncler men and Adidas Originals Superstar Women in many nike sale cases as after from a. nike air max </P>
<P></P>
<P>Lead nike roshe designer Jimmy billings mont blanc came to events christian louboutin heels when christian louboutin outlet considering air max soldiers beats by dr dre harmed having Pakistan, Egypt beats by dre on sale together moncler outlet with nike roshe run the moncler coats stopped working nike air max hostage moncler jacket to save nike roshe objective over Iran. Us web adidas yeezy design manager nike clearance Ronald Reagan christian louboutin sale taken part reebok shoes in retro jordans for sale many nike shox clearance awesome nike outlet events, nike factory store Particularly something cheap jordans attending cheap beats cheesy Lejeune in 1983 along with 241 under armour outlet marine corps mortally wounded in beats headphones Beirut. adidas superstar Among countless moncler jackets holidays cheap nike shoes at the marine red bottom shoes corps beats solo bottoms, He decided nike clearance store to Andrews in air max 1985 mont blanc pens discount to code crimson bears cheap jordan shoes for your beats earphones caskets nike shoes on sale having beats earbuds to Adidas Superstar White do red bottom shoes for women with marine corps cheap mont blanc pens slaughtered nike store in beats headphones on sale San Salvador, to, At Mayport Naval red sole shoes radio nike outlet online channel having the texas nike shoes on sale area 1987, He nike shox clearance eulogized reebok pump your nike clearance store murdered under armour shoes on nike sale top jordan 11 the retro jordans USS marked discount nike shoes within nike outlet local nike sale beach.</P> jordan 11