Flash CS3 Tutorial, Sound Basics

1 - I can do better 2 - Jury's out 3 - Pretty darn good 4 - Splendiferous 5 - Awesometastic by 2 people | Log in to rate

Ranked #4,084 in How-To, #43,152 overall

Flash CS3 Tutorial, Sound

This Flash CS3 Tutorial is designed to help the reader learn some of the basics involved with incorporating sound into your Flash Game or website.

Links to some Great Flash CS3 Tutorials 

FLash CS3 Tutorials using ActionScript 3.0

Here is a list of a few other Flash CS3 Tutorials
F2- Flash CS3 Tutorials
Gordon French is a Flash Developer and this is the home for His Free Flash CS3 Tutorials
Flash CS3 Tutorials
List of Flash CS3 Tutorials and ActionScript 3.0 Tutorials
Flash CS3 Tutorial, Repeat Actions
ActionScript 3.0 Tutorial on using Repeat Actions to Control Actions.
Flash CS3 Tutorial, Preloader
ActionScript 3.0 Tutorial on how to make preloader.
F2-4Kids.com
Educational Games, Kids online coloring book, This is a website dedicated to the education of Children. It started as a project to help my children develop there computer skill and has turned into F2-4Kids.com
Flash CS3 Tutorial, Sound Basics
F2- Flash CS3 Tutorials Gordon French is a Flash Developer. You have found His Free Flash CS3 TutorialsFlash CS3 Tutorial, Sound ActionScript 3.0 Tutorial on using sound.Flash CS3 Tutorial Hello fellow Flash...

Sound 

Flash CS3 Tutorial over Sound

In this Flash CS3 Tutorial I am going to go over Using Sound, after all what Flash game would be complete with out the great sound effects. In Flash CS3, there are basically three ways to play a sound:

1. Import the sound into the library, then add the sound to a key frame in the time line.
2. Import the sound into the library and then use ActionScript to dynamically control the sound.
3. Use ActionScript to dynamically load and play the sound.

This Flash CS3 Tutorial is not really going to cover the first way to play a sound. You should know how to import an image into your library, you import a sound the same way. And just as you would drag an instance of an image onto the stage, you can also drag a sound onto the stage. The sound will simply play every time the key frame plays. Let work on the second way of playing a sound.

A sound file has already been imported into the library. However, if you wish to use your own audio file you can do so by going to File - Import - Import to Library, and select an audio file . Flash CS3 by default will allow you to import, AIF, WAV and MP3 files. There are additional plug ins that enable more files types. Right Click the audio file called Ring.wav. Select Linkage, Check export for ActionScript, leave the base class alone, but you may change the Class to any name you can remember. This CS3 Tutorial is simply going to delete the .wav from the Class name, thus calling the sound Ring.
CS3 Linkage Panel

Now, something needs to be done to call the sound. As normal select the first key frame on the actions layer and press F9 to open the actions panel. In Flash CS3 using ActionScript you need to create a new instance of just bout anything you want to work with. So, create a new instance of the sound by creating a new variable and setting it to the sound. In the example code the variable phoneRing was created, set as equal to a new instance of Ring. The next line of code actually tells flash to play the sound. After typing, or copying and pasting the code to your file, you may test it.

var phoneRing:Ring = new Ring()
phoneRing.play()

Press Control-Enter to hear your sound play once..

The last method of playing a sound is to load the sound dynamically. The advantage to dynamically load sounds is that the sounds will not increase the size of your .swf, thereby keeping the download times lower. Copy the code from the example and paste it in the actions panel below the code that makes the phone ring. URLRquest is a new method introduced in ActionScript 3.0. The getURL method no longer exists, therefore you may want to get familiar with URLRequest, but not in this CS3 Tutorial. In the example code you are simply telling Flash to go get the file listed in between the quotation marks. You can use http:// if the file is not located next to the .swf. Next in the example code, the variable Music is created and defined as a sound. Lastly, the variable music is loaded with the file from the URLRequest. At this point the sound is loaded but nothing is being done with it. Lets do something with it.

var yourRequest:URLRequest = new URLRequest ("SideOfABullet.mp3")
var Music:Sound = new Sound()
Music.load(yourRequest)

You should have noticed the stop and play button located in the start01.flv file. The final part of this Flash CS3 tutorial will be using those buttons. Before, ActionsScript can control the sound it needs to have a soundChannel defined. The example code creates a variable called controlMusic and data types it as a sound channel. You can then control the sound by simple calling on the variable controlMusic.

var controlMusic:SoundChannel

Add the final example code to the actions panel. You should be familiar with most of this code. You are simple adding event listeners to the stop and play buttons that were created for you. It is the code inside the events that should be new. First when the play button is clicked the sound channel you created earlier is set a Music.play(). remember you earlier defined Music as being equal to the audio file loaded when the .swf is called. So, the code associated with the play button is simple telling the music to play. It would stand to reason that the code associated with the stop button would then simply tell the music to stop. Just, remember that you have to control the sound channel, and not the sound directly.

play_btn.addEventListener(MouseEvent.CLICK, playMusic)
function playMusic(event:MouseEvent):void{
controlMusic= Music.play()
};

stop_btn.addEventListener(MouseEvent.CLICK, stopMusic)
function stopMusic(event:MouseEvent):void{
controlMusic.stop()
};

Press Control-Enter and test the file.

Congratulations, you should now be able to add sound to your website, note that you do not need to make the buttons play music, you have the basic code to make your navigation play a chime when clicked.

Download Flash CS3 Source Files

New RSS: Add Your Own Feed 

Gordon's Picks

Here is a list of some of my favorite flash related web sites.

Loading Fetching RSS feed... please stand by

Flash CS3 stuff from Amazon 

Flash CS3 Tutorial, sound

Flash CS3 Video Tutorials 

Great Flash Tutorials from Utube

Here are a few more great Flash CS3 Tutorials
YouTube thumbnail
Adobe Flash Tutorial -- Basic ...

Runtime: 9:18 | 390463 views | Comments

YouTube thumbnail
KnowFlash.com - Create A Carto...

Runtime: 6:50 | 339854 views | Comments

YouTube thumbnail
Scrolling Thumbnails w/ Mouse ...

Runtime: 30:35 | 257544 views | Comments

automatically generated by YouTube"

by FrenchSquared

Gordon French is a Flash Programmer and Flash Designer. Check out My site at
Gordon French
Flash Tutorials
F2-4Kids.com.com
IT Admin
CSS How To (more)

Explore related pages

Create a Lens!