Properties

Methods

SoundManager class

SoundManager

extends EventDispatcher

 

 

Overview

Author

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

Version

1.4 VERSION HISTORY: 1.4 - General refactoring. - Added areAllMuted getter. Fixed bug where if muteAllSounds() was called, playing a sound after that caused it to play rather than stay muted. - Fixed bug where calling muteAllSounds() didn't mute sounds that were being tweened at the same time (thanks Milan Orszagh). - Reverted to TweenLite for default fading behavior. - Reconfigured SoundItem to not extend sound and be its own object so that we can add preloaded sounds without hassle. - Added addPreloadedSound() method to add sounds that are loaded by an external loading system (thanks Nuajan for the idea). - Renamed events being fired by SoundManagerEvent to be more appropriate with what's happening. - Added SoundManagerEvent.SOUND_ITEM_PLAY_COMPLETE event. - Added a destroy() method to SoundItem to clean up for garbage collection. 1.3 - Added the new SoundItem class so that each sound is strongly typed rather than being a generic Object. When using sounds in your library, your sound MUST extend com.reintroducing.sound.SoundItem and NOT flash.media.Sound. Set this as the Base class in the properties panel for each library sound. - Added the getSoundItem() method and removed getSoundObject() method in favor of using the new SoundItem class. - Added the SoundManagerEvent and set the manager to fire off appropriate events. - Changed to TweenMax for default fading behavior. 1.2 - Removed ability to play the sound again if it is already playing (causes conflict with stopAllSounds). To play the same sound at the same time, add the sound under a differnet name (thanks Yu-Chung Chen). - Fixed bug where playSound() wouldn't play from specified position if the sound was paused (thanks Yu-Chung Chen). 1.1 - Fixed bug where calling playSound() on a sound that was muted by muteAllSounds() was causing it to play. Use unmuteAllSounds() to resume playback of muted sounds.

Description

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

The SoundManager can load external sounds, play sounds loaded through an asset loader, 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.

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


Properties

 

sounds

Usage

public function get sounds():Array

Description


 

areAllMuted

Usage

public function get areAllMuted():Boolean

Description


Methods

 

addSound

Usage

private function addSound($linkageID:*, $preloadedSound:Sound, $path:String, $name:String, $buffer:Number = 1000, $checkPolicyFile:Boolean = false):Boolean

Description

Returns

Nothing
 

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
 

addPreloadedSound

Usage

public function addPreloadedSound($sound:Sound, $name:String):Boolean

Description

Adds a sound that was preloaded by an external library to the sounds dictionary for playing in the future.

Parameters

$sound
The sound object that was preloaded
$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
 

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, $resumeTween:Boolean = true):void

Description

Plays or resumes a sound from the sound dictionary with the specified name. If the sounds in the dictionary were muted by the muteAllSounds() method, no sounds are played until unmuteAllSounds() is called.

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)
$resumeTween
A boolean that indicates if a faded sound's volume should resume from the last saved state (default: true)

Returns

void
 

pauseSound

Usage

public function pauseSound($name:String, $pauseTween:Boolean = true):void

Description

Pauses the specified sound.

Parameters

$name
The string identifier of the sound
$pauseTween
A boolean that either pauses the fadeTween or allows it to continue (default: true)

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
 

playAllSounds

Usage

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

Description

Plays all the sounds that are in the sound dictionary.

Parameters

$resumeTweens
A boolean that resumes all unfinished fade tweens (default: true)
$useCurrentlyPlayingOnly
A boolean that only plays the sounds which were currently playing before a pauseAllSounds() or stopAllSounds() call (default: false)

Returns

void
 

pauseAllSounds

Usage

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

Description

Pauses all the sounds that are in the sound dictionary.

Parameters

$pauseTweens
A boolean that either pauses each SoundItem's fadeTween or allows them to continue (default: true)
$useCurrentlyPlayingOnly
A boolean that only pauses the sounds which are currently playing (default: true)

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
 

fadeSound

Usage

public function fadeSound($name:String, $targVolume:Number = 0, $fadeLength:Number = 1, $stopOnComplete:Boolean = false):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)
$stopOnComplete
Added by Danny Miller from K2xL, stops the sound once the fade is done if set to true

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
 

getSoundItem

Usage

public function getSoundItem($name:String):SoundItem

Description

Gets the SoundItem instance of the specified sound.

Parameters

$name
The string identifier of the SoundItem

Returns

SoundItem The SoundItem
 

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
 

onSoundLoadError

Usage

private function onSoundLoadError($evt:IOErrorEvent):void

Description

Dispatched when an external sound can't load and produces an error.

Returns

Nothing
 

onSoundLoadProgress

Usage

private function onSoundLoadProgress($evt:ProgressEvent):void

Description

Dispatched when an external sound is loading.

Returns

Nothing
 

onSoundLoadComplete

Usage

private function onSoundLoadComplete($evt:Event):void

Description

Dispatched when an external sound is fully loaded.

Returns

Nothing
 

handleFadeComplete

Usage

private function handleFadeComplete($evt:SoundManagerEvent):void

Description

Dispatched once a sound's fadeTween is completed if the sound was called to fade.

Returns

Nothing
 

handleSoundPlayComplete

Usage

private function handleSoundPlayComplete($evt:SoundManagerEvent):void

Description

Dispatched when a SoundItem has finished playback.

Returns

Nothing
Window size: 2458 x 1414
Viewport size: 2458 x 1276