Last active
April 19, 2022 09:38
-
-
Save KinoAR/4d026e9095f85bb70eda664fe280887a to your computer and use it in GitHub Desktop.
An example of a FlxSignal in action.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import flixel.util.FlxSignal; | |
// for signals that don't need data, use FlxSignal | |
var signal = new FlxSignal(); | |
// for signals that need data, use FlxTypedSignal with the correct function type | |
var stringSignal = new FlxTypedSignal<String->Void>(); | |
function noParamCallback() { | |
trace('Dispatched void event'); | |
} | |
function showTextCallback(value:String) { | |
trace(value); | |
} | |
//Registering the callbacks | |
signal.add(noParamCallback); | |
stringSignal.add(showTextCallback); | |
stringSignal.add((x)->{trace(x + " Not so good");}); | |
//Sending out the event | |
stringSignal.dispatch('Hello World'); //Prints Hello World and also 'Hello World Not so good' | |
signal.dispatch(); //Prints Dispatched Event |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment