Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace FlxSound.onComplete with FlxSound.onFinish #3336

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion flixel/sound/FlxSound.hx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import flixel.math.FlxMath;
import flixel.math.FlxPoint;
import flixel.system.FlxAssets.FlxSoundAsset;
import flixel.tweens.FlxTween;
import flixel.util.FlxSignal;
import flixel.util.FlxStringUtil;
import openfl.events.Event;
import openfl.events.IEventDispatcher;
Expand Down Expand Up @@ -69,10 +70,16 @@ class FlxSound extends FlxBasic
*/
public var autoDestroy:Bool;

/**
* Signal that is dispatched on sound complete.
*/
public final onFinish:FlxSignal;

/**
* Tracker for sound complete callback. If assigned, will be called
* each time when sound reaches its end.
*/
@:deprecated("`FlxSound.onComplete` is deprecated! Use `FlxSound.onFinish` instead.")
public var onComplete:Void->Void;

/**
Expand Down Expand Up @@ -216,6 +223,7 @@ class FlxSound extends FlxBasic
public function new()
{
super();
onFinish = new FlxSignal();
reset();
}

Expand Down Expand Up @@ -244,12 +252,13 @@ class FlxSound extends FlxBasic
amplitudeLeft = 0;
amplitudeRight = 0;
autoDestroy = false;

if (_transform == null)
_transform = new SoundTransform();
_transform.pan = 0;
}

@:haxe.warning("-WDeprecated")
override public function destroy():Void
{
// Prevents double destroy
Expand All @@ -276,6 +285,8 @@ class FlxSound extends FlxBasic
_sound = null;
}

onFinish.removeAll();

onComplete = null;

super.destroy();
Expand Down Expand Up @@ -431,12 +442,15 @@ class FlxSound extends FlxBasic
}
#end

@:haxe.warning("-WDeprecated")
function init(Looped:Bool = false, AutoDestroy:Bool = false, ?OnComplete:Void->Void):FlxSound
{
looped = Looped;
autoDestroy = AutoDestroy;
updateTransform();
exists = true;
onFinish.removeAll();
onFinish.add(onComplete);
onComplete = OnComplete;
#if FLX_PITCH
pitch = 1;
Expand Down Expand Up @@ -636,8 +650,11 @@ class FlxSound extends FlxBasic
* An internal helper function used to help Flash
* clean up finished sounds or restart looped sounds.
*/
@:haxe.warning("-WDeprecated")
function stopped(?_):Void
{
onFinish.dispatch();

if (onComplete != null)
onComplete();

Expand Down
Loading