Sound programming
Sound instances
You have been using sound during Flash basic course and should remember how to install stream and event sound in the timeline and how to edit sound with the envelop.However sound in Flash is also may be manipulated programmatically. The same as movie symbols are children of MovieClip objecta and input and dynamic texts are children of TextField object – sounds may be considered as children of Sound object.
New sound instances may be created and attached in the same way as movie symbols work.
- Find a short mp3 sound and import it to the Flash file
- In the Linkage enter the linkage identifier for the sound for example "sound1". Don't forget to enter "import in the first frame" to be it available to be taken directly from the library
- On the stage add two buttons. Enter the following code for the first button
on(release) { s1 = new Sound(); s1.attachSound("sound1"); s1.start(); }At first we created new instance of the Sound object. Then the sound is attached from the library. And at last sound starts. - For the second button enter this code
s.stop();
- Test the movie. Sound must run and stop when buttons are clicked
-
One very important performance consideration. In Publish Settings for Flash you need to check "Override sound settings" box. After that quality of SWF sound will be changed to what you wish. If this box is unchecked – sound will be published as in the library and your flash file will be of the original quality but may be very large in size.