Methods

SoundManager class

SoundManager

 

 

 

Overview

Author

Matt Przybylski [http://www.reintroducing.com]

Version

1.0

Description

The SoundManager is a singleton that allows you to have various ways to control sounds in your project.

The SoundManager can load external or library sounds, pause/mute/stop/control volume for one or more sounds at a time, fade sounds up or down, and allows additional control to sounds not readily available through the default classes.

This class is dependent on TweenLite (http://www.tweenlite.com) to aid in easily fading the volume of the sound.


Methods

 

addLibrarySound

Usage

public function addLibrarySound($linkageID:*, $name:String):Boolean

Description

Adds a sound from the library to the sounds dictionary for playing in the future.

Parameters

$linkageID
The class name of the library symbol that was exported for AS
$name
The string identifier of the sound to be used when calling other methods on the sound

Returns

Boolean A boolean value representing if the sound was added successfully
 

addExternalSound

Usage

public function addExternalSound($path:String, $name:String, $buffer:Number = 1000, $checkPolicyFile:Boolean = false):Boolean

Description

Adds an external sound to the sounds dictionary for playing in the future.

Parameters

$path
A string representing the path where the sound is on the server
$name
The string identifier of the sound to be used when calling other methods on the sound
$buffer
The number, in milliseconds, to buffer the sound before you can play it (default: 1000)
$checkPolicyFile
A boolean that determines whether Flash Player should try to download a cross-domain policy file from the loaded sound's server before beginning to load the sound (default: false)

Returns

Boolean A boolean value representing if the sound was added successfully
 

removeSound

Usage

public function removeSound($name:String):void

Description

Removes a sound from the sound dictionary. After calling this, the sound will not be available until it is re-added.

Parameters

$name
The string identifier of the sound to remove

Returns

void
 

removeAllSounds

Usage

public function removeAllSounds():void

Description

Removes all sounds from the sound dictionary.

Returns

void
 

playSound

Usage

public function playSound($name:String, $volume:Number = 1, $startTime:Number = 0, $loops:int = 0):void

Description

Plays or resumes a sound from the sound dictionary with the specified name.

Parameters

$name
The string identifier of the sound to play
$volume
A number from 0 to 1 representing the volume at which to play the sound (default: 1)
$startTime
A number (in milliseconds) representing the time to start playing the sound at (default: 0)
$loops
An integer representing the number of times to loop the sound (default: 0)

Returns

void
 

stopSound

Usage

public function stopSound($name:String):void

Description

Stops the specified sound.

Parameters

$name
The string identifier of the sound

Returns

void
 

pauseSound

Usage

public function pauseSound($name:String):void

Description

Pauses the specified sound.

Parameters

$name
The string identifier of the sound

Returns

void
 

playAllSounds

Usage

public function playAllSounds($useCurrentlyPlayingOnly:Boolean = false):void

Description

Plays all the sounds that are in the sound dictionary.

Parameters

$useCurrentlyPlayingOnly
A boolean that only plays the sounds which were currently playing before a pauseAllSounds() or stopAllSounds() call (default: false)

Returns

void
 

stopAllSounds

Usage

public function stopAllSounds($useCurrentlyPlayingOnly:Boolean = true):void

Description

Stops all the sounds that are in the sound dictionary.

Parameters

$useCurrentlyPlayingOnly
A boolean that only stops the sounds which are currently playing (default: true)

Returns

void
 

pauseAllSounds

Usage

public function pauseAllSounds($useCurrentlyPlayingOnly:Boolean = true):void

Description

Pauses all the sounds that are in the sound dictionary.

Parameters

$useCurrentlyPlayingOnly
A boolean that only pauses the sounds which are currently playing (default: true)

Returns

void
 

fadeSound

Usage

public function fadeSound($name:String, $targVolume:Number = 0, $fadeLength:Number = 1):void

Description

Fades the sound to the specified volume over the specified amount of time.

Parameters

$name
The string identifier of the sound
$targVolume
The target volume to fade to, between 0 and 1 (default: 0)
$fadeLength
The time to fade over, in seconds (default: 1)

Returns

void
 

muteAllSounds

Usage

public function muteAllSounds():void

Description

Mutes the volume for all sounds in the sound dictionary.

Returns

void
 

unmuteAllSounds

Usage

public function unmuteAllSounds():void

Description

Resets the volume to their original setting for all sounds in the sound dictionary.

Returns

void
 

setSoundVolume

Usage

public function setSoundVolume($name:String, $volume:Number):void

Description

Sets the volume of the specified sound.

Parameters

$name
The string identifier of the sound
$volume
The volume, between 0 and 1, to set the sound to

Returns

void
 

getSoundVolume

Usage

public function getSoundVolume($name:String):Number

Description

Gets the volume of the specified sound.

Parameters

$name
The string identifier of the sound

Returns

Number The current volume of the sound
 

getSoundPosition

Usage

public function getSoundPosition($name:String):Number

Description

Gets the position of the specified sound.

Parameters

$name
The string identifier of the sound

Returns

Number The current position of the sound, in milliseconds
 

getSoundDuration

Usage

public function getSoundDuration($name:String):Number

Description

Gets the duration of the specified sound.

Parameters

$name
The string identifier of the sound

Returns

Number The length of the sound, in milliseconds
 

getSoundObject

Usage

public function getSoundObject($name:String):Sound

Description

Gets the sound object of the specified sound.

Parameters

$name
The string identifier of the sound

Returns

Sound The sound object
 

isSoundPaused

Usage

public function isSoundPaused($name:String):Boolean

Description

Identifies if the sound is paused or not.

Parameters

$name
The string identifier of the sound

Returns

Boolean The boolean value of paused or not paused
 

isSoundPausedByAll

Usage

public function isSoundPausedByAll($name:String):Boolean

Description

Identifies if the sound was paused or stopped by calling the stopAllSounds() or pauseAllSounds() methods.

Parameters

$name
The string identifier of the sound

Returns

Number The boolean value of pausedByAll or not pausedByAll