Packageorg.flixel
Classpublic class FlxSound
InheritanceFlxSound Inheritance FlxBasic Inheritance Object

This is the universal flixel sound object, used for streaming, music, and sound effects.



Public Properties
 PropertyDefined By
 Inheritedactive : Boolean
Controls whether update() is automatically called by FlxState/FlxGroup.
FlxBasic
 Inherited_ACTIVECOUNT : uint
[static]
FlxBasic
 Inheritedalive : Boolean
Useful state for many game objects - "dead" (!alive) vs alive.
FlxBasic
  amplitude : Number
Stores the average wave amplitude of both stereo channels
FlxSound
  amplitudeLeft : Number
Just the amplitude of the left stereo channel
FlxSound
  amplitudeRight : Number
Just the amplitude of the left stereo channel
FlxSound
  artist : String
The ID3 artist name.
FlxSound
  autoDestroy : Boolean
Whether to call destroy() when the sound has finished.
FlxSound
 Inheritedcameras : Array
An array of camera objects that this object will use during draw().
FlxBasic
 Inheritedexists : Boolean
Controls whether update() and draw() are automatically called by FlxState/FlxGroup.
FlxBasic
 InheritedID : int
IDs seem like they could be pretty useful, huh? They're not actually used for anything yet though.
FlxBasic
 InheritedignoreDrawDebug : Boolean
Setting this to true will prevent the object from appearing when the visual debug mode in the debugger overlay is toggled on.
FlxBasic
  name : String
The ID3 song name.
FlxSound
  survive : Boolean
Whether or not this sound should be automatically destroyed when you switch states.
FlxSound
 Inheritedvisible : Boolean
Controls whether draw() is automatically called by FlxState/FlxGroup.
FlxBasic
 Inherited_VISIBLECOUNT : uint
[static]
FlxBasic
  volume : Number
Set volume to a value between 0 and 1 to change how this sound is.
FlxSound
  x : Number
The X position of this sound in world coordinates.
FlxSound
  y : Number
The Y position of this sound in world coordinates.
FlxSound
Protected Properties
 PropertyDefined By
  _channel : SoundChannel
Internal tracker for a Flash sound channel object.
FlxSound
  _fadeInTimer : Number
Internal timer for fading in the sound playback.
FlxSound
  _fadeInTotal : Number
Internal helper for fading in sounds.
FlxSound
  _fadeOutTimer : Number
Internal timer used to keep track of requests to fade out the sound playback.
FlxSound
  _fadeOutTotal : Number
Internal helper for fading out sounds.
FlxSound
  _looped : Boolean
Internal tracker for whether the sound is looping or not.
FlxSound
  _pan : Boolean
Internal tracker for whether to pan the sound left and right.
FlxSound
  _pauseOnFadeOut : Boolean
Internal flag for whether to pause or stop the sound when it's done fading out.
FlxSound
  _position : Number
Internal tracker for the position in runtime of the music playback.
FlxSound
  _radius : Number
Internal tracker for the maximum effective radius of this sound (for proximity and panning).
FlxSound
  _sound : Sound
Internal tracker for a Flash sound object.
FlxSound
  _target : FlxObject
Internal tracker for the sound's "target" (for proximity and panning).
FlxSound
  _transform : SoundTransform
Internal tracker for a Flash sound transform object.
FlxSound
  _volume : Number
Internal tracker for how loud the sound is.
FlxSound
  _volumeAdjust : Number
Internal tracker for total volume adjustment.
FlxSound
Public Methods
 MethodDefined By
  
The FlxSound constructor gets all the variables initialized, but NOT ready to play a sound yet.
FlxSound
  
destroy():void
[override] Clean up memory.
FlxSound
 Inherited
draw():void
Override this function to control how the object is drawn.
FlxBasic
 Inherited
drawDebug(Camera:FlxCamera = null):void
Override this function to draw custom "debug mode" graphics to the specified camera while the debugger's visual mode is toggled on.
FlxBasic
  
fadeIn(Seconds:Number):void
Call this function to make a sound fade in over a certain time interval (calls play() automatically).
FlxSound
  
fadeOut(Seconds:Number, PauseInstead:Boolean = false):void
Call this function to make this sound fade out over a certain time interval.
FlxSound
  
Returns the currently selected "real" volume of the sound (takes fades and proximity into account).
FlxSound
  
kill():void
[override]
FlxSound
  
loadEmbedded(EmbeddedSound:Class, Looped:Boolean = false, AutoDestroy:Boolean = false):FlxSound
One of two main setup functions for sounds, this function loads a sound from an embedded MP3.
FlxSound
  
loadStream(SoundURL:String, Looped:Boolean = false, AutoDestroy:Boolean = false):FlxSound
One of two main setup functions for sounds, this function loads a sound from a URL.
FlxSound
  
pause():void
Call this function to pause this sound.
FlxSound
  
play(ForceRestart:Boolean = false):void
Call this function to play the sound - also works on paused sounds.
FlxSound
 Inherited
postUpdate():void
Post-update is called right after update() on each object in the game loop.
FlxBasic
 Inherited
preUpdate():void
Pre-update is called right before update() on each object in the game loop.
FlxBasic
  
proximity(X:Number, Y:Number, Object:FlxObject, Radius:Number, Pan:Boolean = true):FlxSound
Call this function if you want this sound's volume to change based on distance from a particular FlxCore object.
FlxSound
  
resume():void
Unpause a sound.
FlxSound
 Inherited
revive():void
Handy function for bringing game objects "back to life".
FlxBasic
  
stop():void
Call this function to stop this sound.
FlxSound
 Inherited
toString():String
Convert object to readable string name.
FlxBasic
  
update():void
[override] Handles fade out, fade in, panning, proximity, and amplitude operations each frame.
FlxSound
  
Call after adjusting the volume to update the sound channel's settings.
FlxSound
Protected Methods
 MethodDefined By
  
An internal function for clearing all the variables used by sounds.
FlxSound
  
gotID3(event:Event = null):void
Internal event handler for ID3 info (i.e.
FlxSound
  
looped(event:Event = null):void
An internal helper function used to help Flash resume playing a looped sound.
FlxSound
  
stopped(event:Event = null):void
An internal helper function used to help Flash clean up and re-use finished sounds.
FlxSound
Property Detail
_channelproperty
protected var _channel:SoundChannel

Internal tracker for a Flash sound channel object.

_fadeInTimerproperty 
protected var _fadeInTimer:Number

Internal timer for fading in the sound playback.

_fadeInTotalproperty 
protected var _fadeInTotal:Number

Internal helper for fading in sounds.

_fadeOutTimerproperty 
protected var _fadeOutTimer:Number

Internal timer used to keep track of requests to fade out the sound playback.

_fadeOutTotalproperty 
protected var _fadeOutTotal:Number

Internal helper for fading out sounds.

_loopedproperty 
protected var _looped:Boolean

Internal tracker for whether the sound is looping or not.

_panproperty 
protected var _pan:Boolean

Internal tracker for whether to pan the sound left and right. Default is false.

_pauseOnFadeOutproperty 
protected var _pauseOnFadeOut:Boolean

Internal flag for whether to pause or stop the sound when it's done fading out.

_positionproperty 
protected var _position:Number

Internal tracker for the position in runtime of the music playback.

_radiusproperty 
protected var _radius:Number

Internal tracker for the maximum effective radius of this sound (for proximity and panning).

_soundproperty 
protected var _sound:Sound

Internal tracker for a Flash sound object.

_targetproperty 
protected var _target:FlxObject

Internal tracker for the sound's "target" (for proximity and panning).

_transformproperty 
protected var _transform:SoundTransform

Internal tracker for a Flash sound transform object.

_volumeproperty 
protected var _volume:Number

Internal tracker for how loud the sound is.

_volumeAdjustproperty 
protected var _volumeAdjust:Number

Internal tracker for total volume adjustment.

amplitudeproperty 
public var amplitude:Number

Stores the average wave amplitude of both stereo channels

amplitudeLeftproperty 
public var amplitudeLeft:Number

Just the amplitude of the left stereo channel

amplitudeRightproperty 
public var amplitudeRight:Number

Just the amplitude of the left stereo channel

artistproperty 
public var artist:String

The ID3 artist name. Defaults to null. Currently only works for streamed sounds.

autoDestroyproperty 
public var autoDestroy:Boolean

Whether to call destroy() when the sound has finished.

nameproperty 
public var name:String

The ID3 song name. Defaults to null. Currently only works for streamed sounds.

surviveproperty 
public var survive:Boolean

Whether or not this sound should be automatically destroyed when you switch states.

volumeproperty 
volume:Number

Set volume to a value between 0 and 1 to change how this sound is.


Implementation
    public function get volume():Number
    public function set volume(value:Number):void
xproperty 
public var x:Number

The X position of this sound in world coordinates. Only really matters if you are doing proximity/panning stuff.

yproperty 
public var y:Number

The Y position of this sound in world coordinates. Only really matters if you are doing proximity/panning stuff.

Constructor Detail
FlxSound()Constructor
public function FlxSound()

The FlxSound constructor gets all the variables initialized, but NOT ready to play a sound yet.

Method Detail
createSound()method
protected function createSound():void

An internal function for clearing all the variables used by sounds.

destroy()method 
override public function destroy():void

Clean up memory.

fadeIn()method 
public function fadeIn(Seconds:Number):void

Call this function to make a sound fade in over a certain time interval (calls play() automatically).

Parameters

Seconds:Number — The amount of time the fade-in operation should take.

fadeOut()method 
public function fadeOut(Seconds:Number, PauseInstead:Boolean = false):void

Call this function to make this sound fade out over a certain time interval.

Parameters

Seconds:Number — The amount of time the fade out operation should take.
 
PauseInstead:Boolean (default = false) — Tells the sound to pause on fadeout, instead of stopping.

getActualVolume()method 
public function getActualVolume():Number

Returns the currently selected "real" volume of the sound (takes fades and proximity into account).

Returns
Number — The adjusted volume of the sound.
gotID3()method 
protected function gotID3(event:Event = null):void

Internal event handler for ID3 info (i.e. fetching the song name).

Parameters

event:Event (default = null) — An Event object.

kill()method 
override public function kill():void

loadEmbedded()method 
public function loadEmbedded(EmbeddedSound:Class, Looped:Boolean = false, AutoDestroy:Boolean = false):FlxSound

One of two main setup functions for sounds, this function loads a sound from an embedded MP3.

Parameters

EmbeddedSound:Class — An embedded Class object representing an MP3 file.
 
Looped:Boolean (default = false) — Whether or not this sound should loop endlessly.
 
AutoDestroy:Boolean (default = false) — Whether or not this FlxSound instance should be destroyed when the sound finishes playing. Default value is false, but FlxG.play() and FlxG.stream() will set it to true by default.

Returns
FlxSound — This FlxSound instance (nice for chaining stuff together, if you're into that).
loadStream()method 
public function loadStream(SoundURL:String, Looped:Boolean = false, AutoDestroy:Boolean = false):FlxSound

One of two main setup functions for sounds, this function loads a sound from a URL.

Parameters

SoundURL:String — A string representing the URL of the MP3 file you want to play.
 
Looped:Boolean (default = false) — Whether or not this sound should loop endlessly.
 
AutoDestroy:Boolean (default = false) — Whether or not this FlxSound instance should be destroyed when the sound finishes playing. Default value is false, but FlxG.play() and FlxG.stream() will set it to true by default.

Returns
FlxSound — This FlxSound instance (nice for chaining stuff together, if you're into that).
looped()method 
protected function looped(event:Event = null):void

An internal helper function used to help Flash resume playing a looped sound.

Parameters

event:Event (default = null) — An Event object.

pause()method 
public function pause():void

Call this function to pause this sound.

play()method 
public function play(ForceRestart:Boolean = false):void

Call this function to play the sound - also works on paused sounds.

Parameters

ForceRestart:Boolean (default = false) — Whether to start the sound over or not. Default value is false, meaning if the sound is already playing or was paused when you call play(), it will continue playing from its current position, NOT start again from the beginning.

proximity()method 
public function proximity(X:Number, Y:Number, Object:FlxObject, Radius:Number, Pan:Boolean = true):FlxSound

Call this function if you want this sound's volume to change based on distance from a particular FlxCore object.

Parameters

X:Number — The X position of the sound.
 
Y:Number — The Y position of the sound.
 
Object:FlxObject — The object you want to track.
 
Radius:Number — The maximum distance this sound can travel.
 
Pan:Boolean (default = true) — Whether the sound should pan in addition to the volume changes (default: true).

Returns
FlxSound — This FlxSound instance (nice for chaining stuff together, if you're into that).
resume()method 
public function resume():void

Unpause a sound. Only works on sounds that have been paused.

stop()method 
public function stop():void

Call this function to stop this sound.

stopped()method 
protected function stopped(event:Event = null):void

An internal helper function used to help Flash clean up and re-use finished sounds.

Parameters

event:Event (default = null) — An Event object.

update()method 
override public function update():void

Handles fade out, fade in, panning, proximity, and amplitude operations each frame.

updateTransform()method 
public function updateTransform():void

Call after adjusting the volume to update the sound channel's settings.