Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 14th, 2012  |  syntax: None  |  size: 1.38 KB  |  hits: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ActionScript play audio
  2. package {
  3.             import flash.media.Sound;
  4.             import flash.net.URLRequest;
  5.  
  6.             public class typeRight extends Sound {
  7.                     public function HelloWorld( ) {
  8.                     load(new URLRequest('./sound.mp3'));
  9.                     play();
  10.                     }
  11.             }
  12.     }
  13.        
  14. package
  15. {
  16.     import flash.display.Sprite;
  17.     import flash.events.Event;
  18.     import flash.events.IOErrorEvent;
  19.     import flash.media.Sound;
  20.     import flash.media.SoundChannel;
  21.     import flash.net.URLRequest;
  22.  
  23.     public class SoundPlayer extends Sprite
  24.     {
  25.         protected var _sound : Sound;
  26.         protected var _channel : SoundChannel;
  27.  
  28.         public function SoundPlayer()
  29.         {
  30.             _sound = new Sound();
  31.             _sound.addEventListener(Event.COMPLETE, soundLoadCompleteHandler);
  32.             _sound.addEventListener(IOErrorEvent.IO_ERROR, loadError);
  33.             _sound.load(new URLRequest("./sound.mp3"));
  34.         }
  35.  
  36.         protected function soundLoadCompleteHandler(evt : Event) : void
  37.         {
  38.             // Use the _channel object to control sound properties such as pan and volume.
  39.             _channel = _sound.play();
  40.         }
  41.  
  42.         protected function loadError(evt : IOErrorEvent) : void
  43.         {
  44.             trace ("ERROR :: " + evt);
  45.             // You could try recovering from the error here.
  46.         }
  47.  
  48.     }
  49. }