FlxInputText callback error - 'Void should be String -> String -> Void'



  • Hello,

    After implementing the FlxInputText class in my game, when I wrote the callback function and linked it to the FlxInputText field, it threw an error:

    Void should be String -> String -> Void

    This is the function in question:

    private function inputEntered():Void
    {
    	trace('input entered');
    }
    

    And this is the FlxInputText field in question:

    	input = new FlxInputText(165, 185, 310, 8, 0x8811EE11, 0x00000000, true);
    	input.passwordMode = true;
    	input.maxLength = 16;
    	input.hasFocus = true;
    	input.callback = inputEntered();
    	add(input);
    

    I researched the problem and it looks like inputEntered() should take two strings as arguments and return a void. I tried this:

    input.callback = inputEntered('a', 'b');
    

    Coupled with this:

    private function inputEntered(string1:String, string2:String):Void
    {
    	trace('input entered');
    }
    

    but it still throws the same error. I'm a beginner, so any help would be appreciated. Thanks!



  • 	input = new FlxInputText(165, 185, 310, 8, 0x8811EE11, 0x00000000, true);
    	input.passwordMode = true;
    	input.maxLength = 16;
    	input.hasFocus = true;
    	input.callback = inputEntered; // no parentheses ( ) here or it will return Void, of course
    	add(input);
    

    Also the first parameter of the callback is the text and the second is the action that changed the text (input, delete, backspace or enter).

    function inputEnter(text:String, action:String) {
        trace('$action has changed the text to $text');
    }
    


  • @DleanJeans Thanks!


Log in to reply