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 2 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
16 changes: 16 additions & 0 deletions 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 var onFinish:FlxSignal;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs to be read only, lets use final

Suggested change
public var onFinish:FlxSignal;
public final onFinish:FlxSignal;

and add onFinish.removeAll(); to destroy() to clear up memory


/**
* 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 @@ -245,11 +252,15 @@ class FlxSound extends FlxBasic
amplitudeRight = 0;
autoDestroy = false;

if (onFinish == null)
onFinish = new FlxSignal();

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

@:haxe.warning("-WDeprecated")
override public function destroy():Void
{
// Prevents double destroy
Expand Down Expand Up @@ -431,12 +442,14 @@ 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.add(onComplete);
onComplete = OnComplete;
#if FLX_PITCH
pitch = 1;
Expand Down Expand Up @@ -636,8 +649,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