Note: I am using ActionScript 2 as this is the language that we chose to develop our game in.
So the first thing youíll want to do is grab the music file you want to play. If you donít have one you can download the track along with the project file for this tutorial here. The format of your audio track should be a .mp3 with a maximum bitrate of 128kbps. If you need a converter for your audio track I would suggest using Super ©. Itís super powerful, has a ton of features and best of all itís free.To import your audio track to your flash project, simply click File -> Import -> Import to Library, browse to your audio file and then click OK. You should now see your audio file in your project library. After that, in your library, go ahead and right click on your newly added audio track and click properties.
This will bring up the above dialog box. Click the check box that says ďExport for ActionScriptĒ Then in the identifier box type a name that will represent this audio track. I have chosen ďDisco.Ē This allows us to call upon our audio file whenever we choose.
For our next step go ahead and create a new layer by clicking on the New Layer button in the bottom left hand side of the Timeline box. Next double click on the name of the new layer and call it ďActions.Ē Then select the first frame on the Actions layer by left clicking once on your mouse. Finally press F9 to bring up the Actions box. Here we will write the three lines of code that will allow us play our previously added audio track.
Now if I scared you with the word code, donít worry. As you can see there are only 3 lines. Itís nothing you canít handle. Although if youíre using this for a Flash game I would expect that you already have some basic experience with ActionScript. The first line creates a new Sound object called myMusic. On the second line we then attach the audio clip with the identifier name ďDisco.Ē After this has been done the audio track is ready to go. As a final step, myMusic.start() will cause the music to play.
Thatís all there is to it! There isnít as much flexibility is AS2 as there is in AS3 however it still works just fine for small games. Listed below are some more methods that you might find useful.
myMusic.setVolume(100); // Takes a number between 0 and 100 myMusic.stop(); // Stops the Sound Object
Iíve learnt a lot in the course of making this game, and I want to share more with everyone. If youíve enjoyed, learnt anything, or have some suggestions for our readers please feel free to leave a few comments at Blackbunny Thanks for reading!