Packagecom.bourre.media.sound
Classpublic class SoundFactory
SubclassesMixSoundFactory

Player version: Flash Player 9.0
Language version: ActionScript 3.0

  The SoundFactory class is a collection of sounds. 
  All sounds put in , must be in the library of one swf and linked with a className.
  You can define the ApplicationDomain which contains your sounds, by default the ApplicationDomain is the current.
  
  You can add, get, remove, play (simple or loop), stop a sound and know if it is registered, is playing thanks to it's className.
  The same sound can be played several times at same time( several channel for the same sound).
  If you stop a sound, all channels wich play it are stopped.
  You can make a pause : it make a pause on all channels.
  You can make a resume : all channels paused resume to their default behaviors.
  


Example
  import com.bourre.media.sound.SoundFactory;
  import com.bourre.media.load.GraphicLoader; 
  import com.bourre.media.load.GraphicLoaderEvent;
  
  public class MaClasse
  { 
    private var _myLoader   : GraphicLoader ;
    private static var _sF   : SoundFactory ; 
    ...
    private function init( url : String ) : void
    {
     var myUrlLoader : URLRequest = new URLRequest(url); // url = "mylibSound1.swf"
     _myLoader = new GraphicLoader();
     _myLoader.addEventListener( GraphicLoaderEvent.onLoadInitEVENT ,callBack );
     _myLoader.load( myUrlLoader );
    }
      public function callBack( e : Event)
    {
     _sF = new SoundFactory();
     _sF.init(_myLoader.getContentLoaderInfo().applicationDomain);
  
     _sF.addSound("sound1");
     _sF.isRegistered("sound1"); // => true
     _sF.isRegistered("sound2"); // => false
  
     var sound : Sound = _sF.getSound("sound1");
     var soundChannel : SoundChannel = sound.play( sound.length/2, 2 );
     _sF.stopSound("sound1");  // the sound is not stopped because it is playing outside of _sF
     soundChannel.stop();   // the sound is stopped
  
     _sF.play("sound1");
     _sF.play("sound1");   // 2 channels play the "sound1"
     _sF.stop("sound1");   // the 2 channels are stopped
     _sF.clear();    // all sounds are moved
    ...
    }
  }
  



Public Methods
 MethodDefined by
  
Constructs a new SoundFactory instance.
SoundFactory
  
addSound(id:String):void
Add a new sound.
SoundFactory
  
addSounds(a:Array):void
Adds a list of sounds.
SoundFactory
  
clear():void
Stops all sounds, clears sounds lists and reset : you must reinitialise it after with init().
SoundFactory
  
getActiveChannel(id:String):Array
Return an Array of all SoundChannel instances use by the id passed-in
SoundFactory
  
getAllSounds():Array
Get all Sound instances stored under passed-in sound's class identifier.
SoundFactory
  
Get all sound's class identifier use
SoundFactory
  
getSound(id:String):Sound
Returns a Sound instance stored under passed-in sound's class identifier : if your SoundFactory isOn() = true : return a Sound or throw a NoSuchElementException if it doesn't exist if your SoundFactory isOn() = true : return a NullSound
SoundFactory
  
goOff():void
Turns "playing" mode off and stops all currently played sounds.
SoundFactory
  
goOn():void
Turns "playing" mode on.
SoundFactory
  
init(applicationDomain:ApplicationDomain = null):void
Defines passed-in applicationDomain as the sound library's applicationDomain.
SoundFactory
  
isOn():Boolean
Checks if "playing" mode is enable or not.
SoundFactory
  
isPlaying(id:String = null):Boolean
Without argument : it return a Boolean to indicate if there is at least one sound is playing.
SoundFactory
  
isRegistered(id:String):Boolean
Check if a sound is already register
SoundFactory
  
pause():void
Pause all sounds.
SoundFactory
  
playSound(id:String):void
Play a sound simply according to its Class identifier in the library : only if isOn() = true
SoundFactory
  
playSoundLoop(id:String):void
Play a sound in loop ( int.MAX_VALUE times ) according to its Class identifier in the library : only if isOn() = true
SoundFactory
  
removeSound(id:String):void
Removes Sound instance stored under passed-in sound's class identifier.
SoundFactory
  
resume():void
Resume all sounds stopped with pause().
SoundFactory
  
stopSound(id:String = null):void
Without argument it stop all channels of all sounds.
SoundFactory
  
toggleOnOff():void
Toggles "playing" mode.
SoundFactory
  
toString():String
Returns the string representation of this instance.
SoundFactory
Constructor detail
SoundFactory()constructor
public function SoundFactory()

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Constructs a new SoundFactory instance.

Method detail
addSound()method
public function addSound(id:String):void

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Add a new sound.

Parameters
id:String — class identifier in the library

Throws
IllegalArgumentException — if sound's class identifier is already use.
 
ClassCastException — if sound's class not found in specified SoundFactory application domain.

See also


Example
    var _sf : SoundFactory = new SoundFactory();
    try
    {
     _sF.addSound("sound1");
     _sF.addSound("sound1");  // generate an IllegalArgumentException : it's already added
     _sF.addSound("badSound");// generate a ClassCastException : this sound's class identifier in the library doesn't exist
    }
    catch( e : IllegalArgumentException )
    {
     trace(e.message); //=>instanceSoundFactory.addSound( sound1 ) failed, 'sound1' id sound is already use
    }
    catch( e : ClassCastException )
    {
     trace(e.message); //=>instanceSoundFactory.addSound( badSound ) failed, 'badSound' class can't be found in specified SoundFactory application domain
    }
   

addSounds()method 
public function addSounds(a:Array):void

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Adds a list of sounds. Add all sounds except for IllegalArgumentException and ClassCastException.

Parameters
a:Array — array of sound's class identifier (in the library)

Throws
IllegalArgumentException — if sound's class identifier is already use.
 
ClassCastException — if sound's class not found in specified SoundFactory application domain.

See also


Example
     var _sf : SoundFactory = new SoundFactory();
     var aSndList : Array = new Array("Sound1", "Sound2", "Sound2","BadSound"); // class identifiers in the library except "BadSound"
     try
     {
      _sf.addSounds( aSndList );
     }
     catch( e : IllegalArgumentException )
     {
     trace(e.message); //=>instanceSoundFactory.addSounds( ["Sound1", "Sound2", "Sound2","BadSound"] ) failed, 'Sound2' id has been already added
     }
     catch( e : ClassCastException )
     {
     trace(e.message); //=>instanceSoundFactory.addSounds( ["Sound1", "Sound2", "Sound2","BadSound"] ) failed, 'BadSound' class can't be found in specified SoundFactory application domain
     }
   

clear()method 
public function clear():void

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Stops all sounds, clears sounds lists and reset : you must reinitialise it after with init().

getActiveChannel()method 
public function getActiveChannel(id:String):Array

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Return an Array of all SoundChannel instances use by the id passed-in

Parameters
id:String — class identifier in the library

Returns
Array — an Array of all SoundChannel instances use by the id passed-in

Throws
NoSuchElementException — if sound's class identifier has not been used currently in your SoundFactory.

See also


Example
var _sf : SoundFactory = new SoundFactory(); _sf.addSound("sound_1"); _sf.addSound("sound_2"); _sf.play("sound_2"); //SoundChannel1 _sf.playSoundLoop("sound_2"); //SoundChannel2 try { _sf.getActiveChannel("sound_2") // => [SoundChannel2,SoundChannel1] inverse order _sf.getActiveChannel("Sound3") // => generate a NoSuchElementException { catch (e : NoSuchElementException) { trace(e);//=> instanceSoundFactory.removeSound(Sound3) : 'Sound3' doesn't exist }

getAllSounds()method 
public function getAllSounds():Array

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Get all Sound instances stored under passed-in sound's class identifier.

Returns
Array — Get all Sound instances stored under passed-in sound's class identifier.

See also


Example
     var _sf : SoundFactory = new SoundFactory();
     _sf.addSounds(new Array("sound2","sound3","sound4"));
     _sf.addSound("sound1");
     _sf.getAllSounds(); //=> [ instance of sound2 as Sound ,instance of sound4 as Sound,instance of sound1 as Sound,instance of sound3 as Sound] NO ORDER GUARANTED !
   

getRegisteredId()method 
public function getRegisteredId():Array

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Get all sound's class identifier use

Returns
Array — an Array of sound's class identifier use

See also


Example
     var _sf : SoundFactory = new SoundFactory();
   _sF.addSound("sound1");
   _sF.addSound("sound2");
   _sF.addSound("sound3");
    _sF.getRegisteredId(); // => ["sound3", "sound2", "sound1"] NO ORDER GUARANTED !
   

getSound()method 
public function getSound(id:String):Sound

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Returns a Sound instance stored under passed-in sound's class identifier : if your SoundFactory isOn() = true : return a Sound or throw a NoSuchElementException if it doesn't exist if your SoundFactory isOn() = true : return a NullSound

Parameters
id:String — class identifier in the library

Returns
Sound — a Sound instance.

Throws
NoSuchElementException — if sound's class identifier has not been used currently in your SoundFactory.

See also


Example
     var _sf : SoundFactory = new SoundFactory();
     
   try
    {
     _sf.addSound("Sound1");
      _sf.addSound("Sound2");
      _sf.getSound("Sound3"); // not been added
    {
    catch (e : NoSuchElementException)
    {
     trace(e.message);//=> instanceSoundFactory.getSound(Sound3) : 'Sound3' doesn't exist
    }
   

goOff()method 
public function goOff():void

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Turns "playing" mode off and stops all currently played sounds.

See also

goOn()method 
public function goOn():void

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Turns "playing" mode on. Sounds are not automatically played : it's just the state.

See also

init()method 
public function init(applicationDomain:ApplicationDomain = null):void

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Defines passed-in applicationDomain as the sound library's applicationDomain. It can be check with Loader.contentLoaderInfo.applicationDomain. To use, only if your sounds are in an external swf. If not, it's automatically initialized to ApplicationDomain.currentDomain in your first sound addition.

Parameters
applicationDomain:ApplicationDomain (default = null) — null it's ApplicationDomain.currentDomain

Throws
IllegalStateException — if your SoundFactory instance is already initialised

Example
   embed method :
   
   import com.bourre.media.sound.SoundFactory;
   import flash.display.Loader;
   
   public class MaClasse
   { 
     [Embed(source="./../../../testBin/SoundFactory.swf", mimeType="application/octet-stream")]
     private static var _SWFBytes  : Class; 
     private static var _sF    : SoundFactory = new SoundFactory();
     private static var _loader  : Loader;
     private static var _apliDomain : ApplicationDomain;
   
     MaClasse._loader = new Loader();
     MaClasse._loader.loadBytes( new MaClasse._SWFBytes() );
     MaClasse._apliDomain = MaClasse._loader.contentLoaderInfo.applicationDomain;
     try
     {
      MaClasse._sF.init( MaClasse._apliDomain );
      MaClasse._sF.init( ApplicationDomain.currentDomain ); // generate a IllegalStateException
     }
     catch ( e : IllegalStateException)
     {
      trace(e.message); //=>instanceSoundFactory.init() failed, SoundFactory can't be initialized twice
     }
   
     ...
   }
   
   loaded method :
   
   import com.bourre.media.sound.SoundFactory;
   import com.bourre.media.load.GraphicLoader; 
   import com.bourre.media.load.GraphicLoaderEvent;
   
   public class MaClasse
   { 
     private var _myLoader   : GraphicLoader ;
     private var _sF    : SoundFactory ; 
     ...
     private function init( url : String ) : void
     {
      var myUrlLoader : URLRequest = new URLRequest(url); // url = "mylibSound1.swf"
      _myLoader = new GraphicLoader();
       _myLoader.addEventListener( GraphicLoaderEvent.onLoadInitEVENT ,callBack );
      _myLoader.load( myUrlLoader );
     }
        public function callBack( e : Event)
     {
      _sF = new SoundFactory();
      try
      {
       _sF.init( _myLoader.getContentLoaderInfo.applicationDomain );
       _sF.init( ApplicationDomain.currentDomain ); // generate a IllegalStateException
      }
      catch ( e : IllegalStateException )
      {
       trace(e.message); //=>instanceSoundFactory.init() failed, SoundFactory can't be initialized twice
      }
     }
   }
   

isOn()method 
public function isOn():Boolean

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Checks if "playing" mode is enable or not.

Returns
Boolean — true is "playing" mode is enable, either false

See also

isPlaying()method 
public function isPlaying(id:String = null):Boolean

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Without argument : it return a Boolean to indicate if there is at least one sound is playing. With argument : it return a Boolean to indicate if the id passed-in is playing

Parameters
id:String (default = null) — class identifier in the library

Returns
Boolean

Throws
NoSuchElementException — if sound's class identifier has not been used currently in your SoundFactory.

See also


Example
     var _sf : SoundFactory = new SoundFactory();
     _sf.addSound("sound_1");
     _sf.addSound("sound_2");
     _sf.play("sound_2");
     
   try
    {
      _sf.isPlaying() // => true
      _sf.isPlaying("sound_1") // => false
     _sf.isPlaying("Sound3")// => generate a NoSuchElementException
    {
    catch (e : NoSuchElementException)
    {
     trace(e);//=> instanceSoundFactory.removeSound(Sound3) : 'Sound3' doesn't exist
    }
   

isRegistered()method 
public function isRegistered(id:String):Boolean

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Check if a sound is already register

Parameters
id:String — class identifier in the library

Returns
Boolean — true : is registered / false : is not registered

See also


Example
     var _sf : SoundFactory = new SoundFactory();
   _sF.addSound("sound1");
   _sF.isRegistered("sound1"); // => true
   _sF.isRegistered("sound2"); // => false
   

pause()method 
public function pause():void

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Pause all sounds. Be careful : it make a goOff()

See also

playSound()method 
public function playSound(id:String):void

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Play a sound simply according to its Class identifier in the library : only if isOn() = true

Parameters
id:String — identifier in the library

See also

playSoundLoop()method 
public function playSoundLoop(id:String):void

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Play a sound in loop ( int.MAX_VALUE times ) according to its Class identifier in the library : only if isOn() = true

Parameters
id:String — identifier in the library

See also

removeSound()method 
public function removeSound(id:String):void

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Removes Sound instance stored under passed-in sound's class identifier.

Parameters
id:String — class identifier in the library

Throws
NoSuchElementException — if sound's class identifier has not been used currently in your SoundFactory .

See also


Example
     var _sf : SoundFactory = new SoundFactory();
     _sf.addSound("sound_1");
     _sf.addSound("sound_2");
     
   try
    {
      var o : Sound = _sf.getSound("Sound3"); // "Sound3" doesn't exist in your factory, but in the library
    {
    catch (e : NoSuchElementException)
    {
     trace(e);//=> instanceSoundFactory.removeSound(Sound3) : 'Sound3' doesn't exist
    }
   

resume()method 
public function resume():void

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Resume all sounds stopped with pause(). It make automaticly a goOn()

See also

stopSound()method 
public function stopSound(id:String = null):void

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Without argument it stop all channels of all sounds. With argument it stop all channel for a sound according to its Class identifier in the library. Only if your instance of SoundFactory isOn().

Parameters
id:String (default = null) — identifier in the library

Throws
NoSuchElementException — if sound's class identifier has not been used currently in your SoundFactory.

See also

toggleOnOff()method 
public function toggleOnOff():void

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Toggles "playing" mode. Uses goOn() or goOff() methods to switch "playing" mode.

See also

toString()method 
public function toString():String

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Returns the string representation of this instance.

Returns
String