Variables

@:value(new FlxSoundGroup())defaultMusicGroup:FlxSoundGroup = new FlxSoundGroup()

The group sounds played via playMusic() are added to unless specified otherwise.

@:value(new FlxSoundGroup())defaultSoundGroup:FlxSoundGroup = new FlxSoundGroup()

The group sounds in load() / play() / stream() are added to unless specified otherwise.

@:value(new FlxTypedGroup<FlxSound>())read onlylist:FlxTypedGroup<FlxSound> = new FlxTypedGroup<FlxSound>()

A list of all the sounds being played in the game.

music:FlxSound

A handy container for a background music object.

@:value([ZERO, NUMPADZERO])muteKeys:Array<FlxKey> = [ZERO, NUMPADZERO]

The keys used to mute / unmute the game (see FlxG.keys for the keys available). Default keys: 0 (and numpad 0). Set to null to deactivate.

@:value(false)muted:Bool = false

Whether or not the game sounds are muted.

@:value(true)soundTrayEnabled:Bool = true

Whether or not the soundTray should be shown when any of the volumeUp-, volumeDown- or muteKeys is pressed.

@:value(1)volume:Float = 1

Set this to a number between 0 and 1 to change the global volume.

@:value([MINUS, NUMPADMINUS])volumeDownKeys:Array<FlxKey> = [MINUS, NUMPADMINUS]

The keys to decrease volume (see FlxG.keys for the keys available). Default keys: - (and numpad -). Set to null to deactivate.

@:value([PLUS, NUMPADPLUS])volumeUpKeys:Array<FlxKey> = [PLUS, NUMPADPLUS]

The key codes used to increase volume (see FlxG.keys for the keys available). Default keys: + (and numpad +). Set to null to deactivate.

volumeHandler:Float ‑> Void

Set this hook to get a callback whenever the volume changes. Function should take the form myVolumeHandler(volume:Float).

Methods

inlinecache(EmbeddedSound:String):Sound

Method for sound caching (especially useful on mobile targets). The game may freeze for some time the first time you try to play a sound if you don't use this method.

Parameters:

EmbeddedSound

Name of sound assets specified in your .xml project file

Returns:

Cached Sound object

cacheAll():Void

Calls FlxG.sound.cache() on all sounds that are embedded. WARNING: can lead to high memory usage.

changeVolume(Amount:Float):Void

Changes the volume by a certain amount, also activating the sound tray.

@:value({ ForceDestroy : false })destroy(ForceDestroy:Bool = false):Void

Called by FlxGame on state changes to stop and destroy sounds.

Parameters:

ForceDestroy

Kill sounds even if persist is true.

@:value({ AutoPlay : false, AutoDestroy : false, Looped : false, Volume : 1 })load(?EmbeddedSound:Null<FlxSoundAsset>, Volume:Float = 1, Looped:Bool = false, ?Group:FlxSoundGroup, AutoDestroy:Bool = false, AutoPlay:Bool = false, ?URL:String, ?OnComplete:() ‑> Void, ?OnLoad:() ‑> Void):FlxSound

Creates a new FlxSound object.

Parameters:

EmbeddedSound

The embedded sound resource you want to play. To stream, use the optional URL parameter instead.

Volume

How loud to play it (0 to 1).

Looped

Whether to loop this sound.

Group

The group to add this sound to.

AutoDestroy

Whether to destroy this sound when it finishes playing. Leave this value set to "false" if you want to re-use this FlxSound instance.

AutoPlay

Whether to play the sound.

URL

Load a sound from an external web resource instead. Only used if EmbeddedSound = null.

OnComplete

Called when the sound finished playing.

OnLoad

Called when the sound finished loading. Called immediately for succesfully loaded embedded sounds.

Returns:

A FlxSound object.

pause():Void

Pause all sounds currently playing.

@:value({ AutoDestroy : true, Looped : false, Volume : 1 })play(EmbeddedSound:FlxSoundAsset, Volume:Float = 1, Looped:Bool = false, ?Group:FlxSoundGroup, AutoDestroy:Bool = true, ?OnComplete:() ‑> Void):FlxSound

Plays a sound from an embedded sound. Tries to recycle a cached sound first.

Parameters:

EmbeddedSound

The embedded sound resource you want to play.

Volume

How loud to play it (0 to 1).

Looped

Whether to loop this sound.

Group

The group to add this sound to.

AutoDestroy

Whether to destroy this sound when it finishes playing. Leave this value set to "false" if you want to re-use this FlxSound instance.

OnComplete

Called when the sound finished playing

Returns:

A FlxSound object.

@:value({ Looped : true, Volume : 1 })playMusic(Music:FlxSoundAsset, Volume:Float = 1, Looped:Bool = true, ?Group:FlxSoundGroup):Void

Set up and play a looping background soundtrack.

Parameters:

Music

The sound file you want to loop in the background.

Volume

How loud the sound should be, from 0 to 1.

Looped

Whether to loop this music.

Group

The group to add this sound to.

resume():Void

Resume playing existing sounds.

showSoundTray():Void

Shows the sound tray if it is enabled.

@:value({ AutoDestroy : true, Looped : false, Volume : 1 })stream(URL:String, Volume:Float = 1, Looped:Bool = false, ?Group:FlxSoundGroup, AutoDestroy:Bool = true, ?OnComplete:() ‑> Void, ?OnLoad:() ‑> Void):FlxSound

Plays a sound from a URL. Tries to recycle a cached sound first. NOTE: Just calls FlxG.sound.load() with AutoPlay == true.

Parameters:

URL

Load a sound from an external web resource instead.

Volume

How loud to play it (0 to 1).

Looped

Whether to loop this sound.

Group

The group to add this sound to.

AutoDestroy

Whether to destroy this sound when it finishes playing. Leave this value set to "false" if you want to re-use this FlxSound instance.

OnComplete

Called when the sound finished playing

OnLoad

Called when the sound finished loading.

Returns:

A FlxSound object.

toggleMuted():Void

Toggles muted, also activating the sound tray.