diff --git a/flixel/system/frontEnds/SoundFrontEnd.hx b/flixel/system/frontEnds/SoundFrontEnd.hx index 4abab4d04a..0a5e6bb07f 100644 --- a/flixel/system/frontEnds/SoundFrontEnd.hx +++ b/flixel/system/frontEnds/SoundFrontEnd.hx @@ -9,6 +9,7 @@ import flixel.system.FlxAssets; import flixel.sound.FlxSound; import flixel.sound.FlxSoundGroup; import flixel.system.ui.FlxSoundTray; +import flixel.util.FlxSignal; import openfl.Assets; import openfl.media.Sound; #if (openfl >= "8.0.0") @@ -35,8 +36,14 @@ class SoundFrontEnd * Set this hook to get a callback whenever the volume changes. * Function should take the form myVolumeHandler(volume:Float). */ + @:deprecated("volumeHandler is deprecated, use onVolumeChange, instead") public var volumeHandler:Float->Void; + /** + * A signal that gets dispatched whenever the volume changes. + */ + public var onVolumeChange(default, null):FlxTypedSignalVoid> = new FlxTypedSignalVoid>(); + #if FLX_KEYBOARD /** * The key codes used to increase volume (see FlxG.keys for the keys available). @@ -328,6 +335,7 @@ class SoundFrontEnd /** * Toggles muted, also activating the sound tray. */ + @:haxe.warning("-WDeprecated") public function toggleMuted():Void { muted = !muted; @@ -337,6 +345,8 @@ class SoundFrontEnd volumeHandler(muted ? 0 : volume); } + onVolumeChange.dispatch(muted ? 0 : volume); + showSoundTray(true); } @@ -448,15 +458,18 @@ class SoundFrontEnd } #end + @:haxe.warning("-WDeprecated") function set_volume(Volume:Float):Float { Volume = FlxMath.bound(Volume, 0, 1); if (volumeHandler != null) { - var param:Float = muted ? 0 : Volume; - volumeHandler(param); + volumeHandler(muted ? 0 : Volume); } + + onVolumeChange.dispatch(muted ? 0 : Volume); + return volume = Volume; } }