SoundFactory
| Kind of class: | public class |
|---|---|
| Package: | com.bourre.media.sound |
| Inherits from: | none |
| Known subclasses: | |
| Classpath: | com.bourre.media.sound.SoundFactory |
| File last modified: | Monday, 24 November 2008, 11:36:46 |
Summary
Constructor
Instance methods
- init (applicationDomain:ApplicationDomain = null) : void
- Defines passed-in applicationDomain as the sound library's applicationDomain.
- isRegistered (id:String) : Boolean
- Check if a sound is already register
- getRegisteredId : Array
- Get all sound's class identifier use
- addSound (id:String) : void
- Add a new sound.
- addSounds (a:Array) : void
- Adds a list of sounds.
- getSound (id:String) : Sound
- Returns a Sound instance stored under passed-in sound's class identifier :
- getAllSounds : Array
- Get all Sound instances stored under passed-in sound's class identifier.
- removeSound (id:String) : void
- Removes Sound instance stored under passed-in sound's class identifier.
- clear : void
- Stops all sounds, clears sounds lists and reset : you must reinitialise it after with init().
- toggleOnOff : void
- Toggles "playing" mode.
- isOn : Boolean
- Checks if "playing" mode is enable or not.
- goOn : void
- Turns "playing" mode on.
- goOff : void
- Turns "playing" mode off and stops all currently played sounds.
- isPlaying (id:String = null) : Boolean
- Without argument : it return a Boolean to indicate if there is at least one sound is playing.
- getActiveChannel (id:String) : Array
- Return an Array of all SoundChannel instances use by the id passed-in
- playSound (id:String) : void
- Play a sound simply according to its Class identifier in the library : only if isOn() = true
- 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
- stopSound (id:String = null) : void
- Without argument it stop all channels of all sounds.
- pause : void
- Pause all sounds.
- resume : void
- Resume all sounds stopped with pause().
- toString : String
- Returns the string representation of this instance.
Constructor
SoundFactory
public function SoundFactory (
)
Constructs a new SoundFactory instance.
Instance methods
addSound
public function addSound (
id:String) : void
Add a new sound.
Parameters:
sound's:
class identifier in the library
Throws:
- com.bourre.error.IllegalArgumentException if sound's class identifier is already use.
- com.bourre.error.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
public function addSounds (
a:Array) : void
Adds a list of sounds. Add all sounds except for IllegalArgumentException and ClassCastException.
Parameters:
an:
array of sound's class identifier (in the library)
Throws:
- com.bourre.error.IllegalArgumentException if sound's class identifier is already use.
- com.bourre.error.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
public function clear (
) : void
Stops all sounds, clears sounds lists and reset : you must reinitialise it after with init().
getActiveChannel
public function getActiveChannel (
id:String) : Array
Return an Array of all SoundChannel instances use by the id passed-in
Parameters:
sound's:
class identifier in the library
Returns:
- an Array of all SoundChannel instances use by the id passed-in
Throws:
- com.bourre.error.NoSuchElementException if sound's class identifier has not been used currently in your SoundFactory.
Example:
- var _sf : SoundFactory = new SoundFactory();
_sf.addSound("sound_1");
_sf.addSound("sound_2");
_sf.play("sound_2");
_sf.playSoundLoop("sound_2");
try
{
_sf.getActiveChannel("sound_2")
_sf.getActiveChannel("Sound3")
{
catch (e : NoSuchElementException)
{
trace(e);
}
getAllSounds
public function getAllSounds (
) : Array
Get all Sound instances stored under passed-in sound's class identifier.
Returns:
- Get all Sound instances stored under passed-in sound's class identifier.
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
public function getRegisteredId (
) : Array
Get all sound's class identifier use
Returns:
- 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
public function 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
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:
sound's:
class identifier in the library
Returns:
- a Sound instance.
Throws:
- com.bourre.error.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
public function goOff (
) : void
Turns "playing" mode off and stops all currently played sounds.
See also:
goOn
public function goOn (
) : void
Turns "playing" mode on.
Sounds are not automatically played : it's just the state.
Sounds are not automatically played : it's just the state.
See also:
init
public function init (
applicationDomain:ApplicationDomain = null) : void
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.
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:
if:
null it's ApplicationDomain.currentDomain
Throws:
- com.bourre.error.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
public function isOn (
) : Boolean
Checks if "playing" mode is enable or not.
Returns:
- true is "playing" mode is enable, either false
See also:
isPlaying
public function isPlaying (
id:String = null) : Boolean
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
With argument : it return a Boolean to indicate if the id passed-in is playing
Parameters:
sound's:
class identifier in the library
Throws:
- com.bourre.error.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
public function isRegistered (
id:String) : Boolean
Check if a sound is already register
Parameters:
sound's:
class identifier in the library
Returns:
- 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
public function pause (
) : void
Pause all sounds.
Be careful : it make a goOff()
Be careful : it make a goOff()
See also:
playSound
public function playSound (
id:String) : void
Play a sound simply according to its Class identifier in the library : only if isOn() = true
Parameters:
Class:
identifier in the library
See also:
playSoundLoop
public function 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
removeSound
public function removeSound (
id:String) : void
Removes Sound instance stored under passed-in sound's class identifier.
Parameters:
sound's:
class identifier in the library
Throws:
- com.bourre.error.NoSuchElementException if sound's class identifier has not been used currently in your SoundFactory .
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
public function resume (
) : void
Resume all sounds stopped with pause().
It make automaticly a goOn()
It make automaticly a goOn()
See also:
stopSound
public function stopSound (
id:String = null) : void
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().
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:
Class:
identifier in the library
Throws:
- com.bourre.error.NoSuchElementException if sound's class identifier has not been used currently in your SoundFactory.
See also:
toggleOnOff
public function toggleOnOff (
) : void
Toggles "playing" mode.
Uses goOn() or goOff() methods to switch "playing" mode.
Uses goOn() or goOff() methods to switch "playing" mode.
toString
public function toString (
) : String
Returns the string representation of this instance.