Callback functions?

36 views
Skip to first unread message

james...@gmail.com

unread,
Apr 18, 2014, 1:05:54 AM4/18/14
to fla...@googlegroups.com
Is there a way to pass a function as a parameter to use as a callback function?

function onComplete(){
// does something else
}

function doSomething(callback:Function){
// do something and when it's done...
callback();
}

doSomething(onComplete);

Mark Knol

unread,
Apr 18, 2014, 2:18:03 AM4/18/14
to fla...@googlegroups.com
Function references work pretty much the same as in AS3. Only in AS3 all function values are of type Function, while in haxe a function type is defined by its arguments.

So instead of onComplete:Function, you should use onComplete:Void->Void. This means that the callback function has no arguments, and does not return anything.

As alternative, you also could use signals https://github.com/markknol/flambe-guide/wiki/Signal-Event-System

james...@gmail.com

unread,
Apr 18, 2014, 12:29:08 PM4/18/14
to fla...@googlegroups.com
Signals look fine. Thanks!
Reply all
Reply to author
Forward
0 new messages