Flash AS3 attachSound – SoundChannel
If you haven’t noticed yet attachSound in Flash AS3 ( actionscript 3 ) is no longer there. Instead use the SoundChannel.
Import the audio file into your library then right-click on it and select Linkage…make sure the “Export for ActionScript” and “Export in first frame” checkboxes are checked. If you are not using your own custom class then just type a unique class name into the “Class” input box (i.e. MySong).
Use the following script to play the sound file:
import flash.media.SoundChannel; import flash.media.Sound; var mySound:MySong = new MySong(); var channel:SoundChannel = mySound.play();
Flash will recognize that the library asset is an audio file so the MySong class (which Flash automatically generates for you) will extend the Sound class… and that means you will be able to access all of the usual Sound methods and properties.
Related Posts:
Posted in: Flash Helps | Comments Off