Accessed via FlxG.sound.

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.

read onlysoundTray:FlxSoundTray

The sound tray display container. A getter for FlxG.game.soundTray.

@: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.0 })load(?embeddedSound:Null<FlxSoundAsset>, volume:Float = 1.0, 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.0 })play(embeddedSound:FlxSoundAsset, volume:Float = 1.0, 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.0 })playMusic(embeddedMusic:FlxSoundAsset, volume:Float = 1.0, looped:Bool = true, ?group:FlxSoundGroup):Void

Set up and play a looping background soundtrack.

Parameters:

embeddedMusic

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.

@:value({ up : false })showSoundTray(up:Bool = false):Void

Shows the sound tray if it is enabled.

Parameters:

up

Whether or not the volume is increasing.

@:value({ autoDestroy : true, looped : false, volume : 1.0 })stream(url:String, volume:Float = 1.0, 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.