Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ActionScript play audio
- package {
- import flash.media.Sound;
- import flash.net.URLRequest;
- public class typeRight extends Sound {
- public function HelloWorld( ) {
- load(new URLRequest('./sound.mp3'));
- play();
- }
- }
- }
- package
- {
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.events.IOErrorEvent;
- import flash.media.Sound;
- import flash.media.SoundChannel;
- import flash.net.URLRequest;
- public class SoundPlayer extends Sprite
- {
- protected var _sound : Sound;
- protected var _channel : SoundChannel;
- public function SoundPlayer()
- {
- _sound = new Sound();
- _sound.addEventListener(Event.COMPLETE, soundLoadCompleteHandler);
- _sound.addEventListener(IOErrorEvent.IO_ERROR, loadError);
- _sound.load(new URLRequest("./sound.mp3"));
- }
- protected function soundLoadCompleteHandler(evt : Event) : void
- {
- // Use the _channel object to control sound properties such as pan and volume.
- _channel = _sound.play();
- }
- protected function loadError(evt : IOErrorEvent) : void
- {
- trace ("ERROR :: " + evt);
- // You could try recovering from the error here.
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment