FlxTween questions (complete callback)

233 views
Skip to first unread message

buazz BELB

unread,
May 11, 2015, 10:06:06 AM5/11/15
to haxef...@googlegroups.com
I have some questions regarding FlxTween:

1. Is it possible to pass custom arguments to the complete callback of a FlxTween? I looked at the API docs and saw that the complete callback takes one argument, the FlxTween. I need to run some code after a tween is complete, but it needs to know some information that isn't stored inside the tween, nor the object being tweened. I'm wondering how to do it.

2. I'd like to run a complete callback only after multiple tweens have finished. Let's say I start 3 tweens one after another, how would I know when all of them have finished? Do I just put the complete callback on the tween with the longest duration? If they all have the same duration, would putting the complete callback on the 3rd tween work the way I want (only be called after all 3 tweens are finished)?

Well, I had another question, but I've forgotten what it was... If I remember, I'll ask.

Thanks

Gama11

unread,
May 11, 2015, 11:09:44 AM5/11/15
to haxef...@googlegroups.com, buaz...@gmail.com
1. Yes, in fact that's possible for any function in Haxe via function binding (super useful for FlxButton / FlxTimer callbacks too). Something like this would do the trick (pseudocode):

function callback(tween:FlxTween, customData:String)
{
   trace
(customData);
}

{ complete: callback.bind("Hello World") }

2. Sounds reasonable. You could also put all of those tweens inside an array and check if all of them are finished yet in the callback before doing anything.

buazz BELB

unread,
May 11, 2015, 1:05:58 PM5/11/15
to haxef...@googlegroups.com, buaz...@gmail.com
Thanks a lot for your quick answer Gama11! 

I had to change the bind call slightly, adding an underscore as the first parameter, like on the Haxe Function Bindings page you linked to.

{ complete: callback.bind(_, "Hello World") }

I don't really understand that Haxe documentation to be honest, but it seems to work with the underscore. Without it, I get a compilation error.

Thanks again.

Gama11

unread,
May 11, 2015, 2:19:27 PM5/11/15
to haxef...@googlegroups.com, buaz...@gmail.com
Ah, right, the argument is added to the end. That's what I get for posting untested pseudocode I guess. :)

Is there anything in particular you don't understand about the Haxe docs? It can be a bit technical.

buazz BELB

unread,
May 11, 2015, 9:20:47 PM5/11/15
to haxef...@googlegroups.com, buaz...@gmail.com
I just don't understand the concept of function binding. It allows you to change the arguments of a function dynamically? Or it doesn't change the original function, but creates a new function with different arguments that then calls the original? Or something else... I'm not sure.

Gama11

unread,
May 12, 2015, 9:45:17 AM5/12/15
to haxef...@googlegroups.com, buaz...@gmail.com
It definitely doesn't change the original function. Not sure how exactly it's implemented, but yeah, it probably creates a new anonymous function that calls your function with the bound arguments.
Reply all
Reply to author
Forward
0 new messages