We look at the the best platforms to use for animations, interactive content and games when considering cross platform compatibility...
Actionscript 3 – Adding sound or music to Flash files
If you want to add sounds or music to a Flash file using only Actionscript 3, this is how you do it:
1. First, you need to import a sound file into your Library, and then allow it to export by actionscript. Call the class something relevant, for example bg_music. The Base class should be flash.media.Sound.
2. In your actionscript layer we first need to allow Flash to import the basic sound class. Near the start of your AS write:
3. Next you need to create a variable instance of your sound from the library:
And an instance of the SoundChannel class so you can hear the sound or music.
4. Next create an instance of your sound or music with the following:
Your final actionscript code should look like this:
5. Then simply add the following code to your actionscript when you want the sound or the music to play: