Skip to content
ClassAudio System@public

FlxSound

Port of org.flixel.FlxSound.

Extends FlxBasic and drives playback through a FlxSoundHandle obtained from the active FlxAudioBackend. All authoritative state (volume, fade, proximity, loop, alive/exists) lives on this object; the handle is a platform-specific playback delegate.

ts
export declare class FlxSound extends FlxBasic

Properties

PropertyModifiersTypeDescription
amplitude-numberSmoothed peak amplitude 0–1 (combined).
amplitudeLeft-numberSmoothed peak amplitude for the left channel (same as amplitude in stereo panner).
amplitudeRight-numberSmoothed peak amplitude for the right channel (same as amplitude in stereo panner).
artist-stringMetadata artist string (informational only).
autoDestroy-booleanIf true, destroy() is called automatically when playback finishes.
effectiveVolumereadonlynumberEffective gain after global, group, instance, and proximity attenuation.
group-FlxSoundGroup | nullHierarchical volume/mute bus used by this sound.
name-stringSound name for identification and debugging.
survive-booleanIf true, this sound survives state switches.
volume-numberPer-instance volume (0–1).
x-numberWorld x position for proximity audio.
y-numberWorld y position for proximity audio.

Methods

attachTo()

ts
attachTo(source: FlxObject, options: FlxSoundAttachmentOptions): FlxSound

Follow a world object and spatialize it relative to a listener. Camera visibility may pause or stop playback automatically.

Parameters:

ParameterTypeDescription
sourceFlxObject-
optionsFlxSoundAttachmentOptions-

Returns: FlxSound

destroy()

ts
destroy(): void

Release the backend handle and clean up.

Returns: void

detach()

ts
detach(): FlxSound

Stop following the attached object and restore ordinary playback.

Returns: FlxSound

fadeIn()

ts
fadeIn(duration: number): void

Fade the volume in from 0 over duration seconds.

Parameters:

ParameterTypeDescription
durationnumber-

Returns: void

fadeOut()

ts
fadeOut(duration: number, callback?: (() => void) | null): void

Fade the volume out over duration seconds.

Parameters:

ParameterTypeDescription
durationnumberFade time in seconds.
callback(() => void) | nullCalled when the fade completes.

Returns: void

getActualVolume()

ts
getActualVolume(): number

Effective volume accounting for global volume and mute.

Returns: number

kill()

ts
kill(): void

Kill the sound: stop playback and mark dead/nonexistent.

Returns: void

loadEmbedded()

ts
loadEmbedded(source: unknown, loop?: boolean, autoDestroy?: boolean): FlxSound

Load an embedded sound asset.

Parameters:

ParameterTypeDescription
sourceunknownAn AudioBuffer, URL string, or asset alias.
loopbooleanWhether the sound should loop.
autoDestroybooleanWhether to auto-destroy when done.

Returns: FlxSound

loadStream()

ts
loadStream(url: string, loop?: boolean, autoDestroy?: boolean): FlxSound

Load a streaming sound from a URL.

Parameters:

ParameterTypeDescription
urlstringThe streaming URL.
loopbooleanWhether the sound should loop.
autoDestroybooleanWhether to auto-destroy when done.

Returns: FlxSound

pause()

ts
pause(): void

Pause playback.

Returns: void

play()

ts
play(forceRestart?: boolean): void

Start or restart playback.

Parameters:

ParameterTypeDescription
forceRestartboolean-

Returns: void

proximity()

ts
proximity(x: number, y: number, target: FlxObject, radius: number, pan?: boolean): FlxSound

Configure proximity-based volume and panning.

Parameters:

ParameterTypeDescription
xnumberSource x position.
ynumberSource y position.
targetFlxObjectThe object to measure distance from (typically the player or camera).
radiusnumberMaximum audible distance.
panbooleanWhether to apply stereo panning based on horizontal offset.

Returns: FlxSound

resume()

ts
resume(): void

Resume from pause.

Returns: void

stop()

ts
stop(): void

Stop playback and reset position.

Returns: void

update()

ts
update(): void

Per-frame update: fades, proximity, auto-destroy, amplitude.

Returns: void

Released under the MIT License.