Flash MX - Sound Object
Import Sound File
-
Select File - Import To Library . Choose your sound file. I usually use .wav files. Try .mp3's if you like.
-
Select Window - Library ( or press F11) to open the library. Right click on the sound file in the library.
- Select "Linkage" from the drop down menu
-
Tick the "Export for Actionscript" box and the "export in first frame " box.
- In the "Identifier" Textfield , type the actionscript name that you will use in your script.
I used "bang". Click "OK" button to close linkages window.
Create a button
- Draw a button, I used a round circle. Select the circle and hit key F8
(or Select Menu Item "Insert" - "Convert to Symbol")
-
In the "Convert to Symbol" dialog box, select the "Button" box, and write a name
in the "Name" TextField. I used "soundButton".
-
Click on the sound button on the stage. Open the Properties window and in the "Instance Name" textfield
write your button's actionscript variable name. I used "sound_btn"
Flash Tutorials in Video Format -
Watch them now at LearnFlash.com
Write code to play Sound
-
Create a new layer in the timeline. ("Insert" - "Layer") . Double click on the layer name and rename it "Control".
This is where we will write our Code.
-
With the first frame of the control layer selected, open the Actions Window (F9 or Menu "window" - "actions").
-
Type this code into the Actions window:
mySound = new Sound();
mySound.attachSound("bang");
sound_btn.onRelease = function() {
mySound.start();
}
-
Test it - Hit (Control + Enter) Keys.
|