SoundFactory

Kind of class:class
Inherits from:none
Known subclasses:
Version:1.0
Author:Francis Bourre
Classpath:com.bourre.medias.sound.SoundFactory
File last modified:Wednesday, 31 October 2007, 07:35:29
SoundFactory defines data holder for Sound object managment.

Load external "MP3" files using loadSound method.

Attach internal sound using addSound or addSounds methods.

SoundFactory add event support with :

Example

function onSoundLoad(e : IEvent) : Void {
    var sID : String = e.soundID;
    sf.playSoundLoop( sID );
}

var sf : SoundFactory = new SoundFactory();
sf.addEventListener( SoundFactory.onSoundLoadEVENT, this);

sf.addSound("sound_1");
sf.addSound("sound_2");
sf.loadSound("http://www.tweenpix.net/background_sound.mp3", "back");

Constructor

SoundFactory

function SoundFactory (
)
Constructs a new SoundFactory instance.

Class properties

onSoundLoadEVENT

static onSoundLoadEVENT:EventType = new EventType("onSoundLoad")
(read,write)
Broadcast when external mp3 file is loaded.
Component metadata:
Event
onSoundLoad

Instance properties

isOn

isOn:Boolean
(read)
Checks if "playing" mode is enable or not.
Returns:
true is "playing" mode is enable, either false

Instance methods

addEventListener

function addEventListener (
e:EventType) : Void
Adds passed-in oL listener for receiving passed-in
t event type.

Take a look at example below to see all possible method call.

Example

var sf : SoundFactory = new SoundFactory();
oEB.addEventListener( SoundFactory.onSoundLoadEVENT, myListener);
Parameters:
t :
Name of the Event.
oL:
Listener object.

addListener

function addListener (
) : Void
Adds passed-in oL listener for receiving all
SoundFactory events.

Example

var sf : SoundFactory = new SoundFactory();
sf.addListener( myListener );
Parameters:
oL:
Listener object

addSound

function addSound (
linkageID:String) : String
Adds new sound to factory.

Example

var sf : SoundFactory = new SoundFactory();
sf.addSound("sound_1");
sf.addSound("sound_2");
Parameters:
linkageID:
Sound identifier in swf file
Returns:
String sound identifier

addSounds

function addSounds (
a:Array) : Void
Adds sounds id list to factory.

Example

var sf : SoundFactory = new SoundFactory();
var aSndList : Array = new Array("sound_1", "sound_2");

sf.addSounds( aSndList );
Parameters:
a:
Array Sounds ID list

clear

function clear (
) : Void
Stops all sounds, clears sounds lists and reset event listeners.

getAllSounds

function getAllSounds (
) : Array
Returns an Array list of stored sounds.
Returns:
Array instance

getSound

function getSound (
sID:String) : Sound
Returns Sound instance stored under passed-in
sID identifier.

Example

var sf : SoundFactory = new SoundFactory();
sf.addSound("sound_1");
sf.addSound("sound_2");

var o : Sound = sf.getSound("sound_1");
Returns:
Sound instance. If no sound is found, an empty
Sound is returned.

goOff

function goOff (
) : Void
Turns "playing" mode off and stops all currently played sounds.

goOn

function goOn (
) : Void
Turns "playing" mode on.

Sounds are not automatically played.

init

function init (
mcTarget:MovieClip) : Void
Defines passed-in mcTarget as sounds container.
Parameters:
mcTarget:
(optional) MovieClip instance

loadSound

function loadSound (
sURL:String, linkageID:String) : String
Loads (or attach) new sound.

If not valid sURL is passed, try to find
linkageID ID in current swf file.

Returns:
String sound identifier

playSoundLoop

function playSoundLoop (
sID:String) : Void
Plays passed-in sID identifier sound in loop mode.

Example

var sf : SoundFactory = new SoundFactory();
sf.addSound("sound_1");
sf.addSound("sound_2");

sf.playSoundLoop("sound_1");

removeEventListener

function removeEventListener (
e:EventType) : Void
Removes passed-in oL listener that suscribed for passed-in
t event.

Example

var sf : SoundFactory = new SoundFactory();
 oEB.removeListener( SoundFactory.onSoundLoadEVENT, myListener);
Parameters:
t :
Name of the Event.
oL:
Listener object.

removeListener

function removeListener (
) : Void
Removes passed-in oL listener for receiving all
SoundFactory events.

Example

sf.removeListener( myListener );
Parameters:
oL:
Listener object.

removeSound

function removeSound (
sID:String) : Void
Removes Sound instance stored under passed-in
sID identifier from factory.

Example

var sf : SoundFactory = new SoundFactory();
sf.addSound("sound_1");
sf.addSound("sound_2");

sf.removeSound("sound_1");

toggleOnOff

function toggleOnOff (
) : Void
Toggles "playing" mode.

Uses goOn or goOff methods to switch
"playing" mode.

toString

function toString (
) : String
Returns the string representation of this instance.
Returns:
the string representation of this instance