class flixel.system.FlxSound extends FlxBasic

Available on all platforms

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

Instance Fields

var amplitude:Float

Stores the average wave amplitude of both stereo channels

var amplitudeLeft:Float

Just the amplitude of the left stereo channel

var amplitudeRight:Float

Just the amplitude of the left stereo channel

var artist:String

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

var autoDestroy:Bool

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

var name:String

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

var pan:Float

Pan amount. -1 = full left, 1 = full right. Proximity based panning overrides this.

var persist:Bool

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

var playing:Bool

Whether or not the sound is currently playing.

var time:Float

The position in runtime of the music playback.

var volume:Float

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

var x:Float

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

var y:Float

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

function new():Void

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

function destroy():Void

function fadeIn(?Duration:Float = 1, ?From:Float = 0, ?To:Float = 1):FlxSound

Helper function that tweens this sound's volume. * *

Duration

The amount of time the fade-in operation should take. *

From

The volume to tween from, 0 by default. *

To

The volume to tween to, 1 by default.

function fadeOut(?Duration:Float = 1, ?To:Float = 0):FlxSound

Helper function that tweens this sound's volume. * *

Duration

The amount of time the fade-out operation should take. *

To

The volume to tween to, 0 by default.

function getActualVolume():Float

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

returns

The adjusted volume of the sound.

function kill():Void

function loadByteArray(Bytes:ByteArray, ?Looped:Bool = false, ?AutoDestroy:Bool = false, ?OnComplete:Void ->Void = null):FlxSound

One of the main setup functions for sounds, this function loads a sound from a ByteArray. * *

Bytes

A ByteArray object. *

Looped

Whether or not this sound should loop endlessly. *

AutoDestroy

Whether or not this FlxSound instance should be destroyed when the sound finishes playing. Default value is false, but FlxG.sound.play() and FlxG.sound.stream() will set it to true by default. *

returns

This FlxSound instance (nice for chaining stuff together, if you're into that).

function loadEmbedded(EmbeddedSound:Dynamic, ?Looped:Bool = false, ?AutoDestroy:Bool = false, ?OnComplete:Void ->Void = null):FlxSound

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

EmbeddedSound

An embedded Class object representing an MP3 file. *

Looped

Whether or not this sound should loop endlessly. *

AutoDestroy

Whether or not this FlxSound instance should be destroyed when the sound finishes playing. Default value is false, but FlxG.sound.play() and FlxG.sound.stream() will set it to true by default. * *

returns

This FlxSound instance (nice for chaining stuff together, if you're into that).

function loadStream(SoundURL:String, ?Looped:Bool = false, ?AutoDestroy:Bool = false, ?OnComplete:Void ->Void = null):FlxSound

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

EmbeddedSound

A string representing the URL of the MP3 file you want to play. *

Looped

Whether or not this sound should loop endlessly. *

AutoDestroy

Whether or not this FlxSound instance should be destroyed when the sound finishes playing. Default value is false, but FlxG.sound.play() and FlxG.sound.stream() will set it to true by default. * *

returns

This FlxSound instance (nice for chaining stuff together, if you're into that).

function onComplete():Void

Tracker for sound complete callback. Default is null. If assigend, will be called * each time when sound reaches its end. Works only on flash and desktop targets.

function pause():FlxSound

Call this function to pause this sound.

function play(?ForceRestart:Bool = false):FlxSound

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

ForceRestart

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.

function proximity(X:Float, Y:Float, TargetObject:FlxObject, Radius:Float, ?Pan:Bool = true):FlxSound

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

X

The X position of the sound. *

Y

The Y position of the sound. *

TargetObject

The object you want to track. *

Radius

The maximum distance this sound can travel. *

Pan

Whether panning should be used in addition to the volume changes (default: true). *

returns

This FlxSound instance (nice for chaining stuff together, if you're into that).

function resume():FlxSound

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

function setPosition(?X:Float = 0, ?Y:Float = 0):Void

Helper function to set the coordinates of this object. * Sound positioning is used in conjunction with proximity/panning. * *

X

The new x position *

Y

The new y position

function stop():FlxSound

Call this function to stop this sound.

function update():Void

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