flixel-addons icon indicating copy to clipboard operation
flixel-addons copied to clipboard

FlxTypeText counterintuitive callback behaviour

Open 6J7KZg2f opened this issue 6 years ago • 5 comments

Currently FlxTypeText.onComplete:Void->Void is public, and "Callback" is an optional paramater of FlxTypeText.start().

However, leaving out the Callback paramater of start() causes onComplete to be overwritten with null, meaning the only time you could meaningfully set onComplete directly is after calling start() but before the animation completes.

We could check for null in start(), but that would prevent you from intentionally nulling the callback when calling start.

I propose either making onComplete private, or removing Callback from start().

I personally lean towards the latter, as it creates less-messy function calls.

Thoughts?

6J7KZg2f avatar Feb 25 '19 06:02 6J7KZg2f

Actually, it seems this was a deliberate change a while ago: #293

Gama11 avatar Feb 25 '19 09:02 Gama11

Okay, in that case what about leaning towards the former of my propositions?

This code:

var myFTT = new FlxTypeText(0, 0, 0, "test");
myFTT.onComplete = function(){trace("yeah nah");};
myFTT.start();

Surely should result in yeah nah appearing in the console.

If that is incorrect usage, I don't believe onComplete should be public.

6J7KZg2f avatar Feb 27 '19 04:02 6J7KZg2f

@winterismute Any thoughts on this, since you made the change originally? Is this a case you considered?

Gama11 avatar Feb 27 '19 09:02 Gama11

The fact is that, depending on the mental model of the person that wants to use the class FlxTypeText, both using null to "force the callback to null" or not to do it might appear as sensible options for the behaviour of "start". I think at this point the best thing would be to remove the parameter from "start" and just have people set it explicitly if they want to use it, so that this does not interfere with the call to "start". A callback parameter could be potentially added to the constructor if we think a common usage of the object might be "attach a callback that you want to have called every time you restart".

winterismute avatar Mar 01 '19 15:03 winterismute

Can this be closed now after #353 ?

migmoog avatar Nov 15 '21 13:11 migmoog