Can't modify preventDefaultKeys?



  • I'm developing for mobile and would like to give the back button on Android a different function than the default of closing the app. I tried accessing FlxG.android.preventDefaultKeys and giving it a value of [FlxAndroidKey.BACK] but unfortunately the app crashes on launch. Testing it on neko using FlxG.keys.preventDefaultKeys reveals that I'm not allowed to access it, which seems to be because FlxKeyManager is only given access permission within the flixel package. Certain fields such as pressed and justPressed can be accessed outside of it because they have the (default, null), but preventDefaultKeys does not.

    Is this a bug or am I just going about this the wrong way?


  • administrators

    Testing it on neko using FlxG.keys.preventDefaultKeys reveals that I'm not allowed to access it

    What makes you say that? Seems to work fine for me.



  • I get Invalid field access on the line where I try access preventDefaultKeys. Everything is up to date.


  • administrators

    Invalid field access is a null reference error - perhaps you're trying to access it too early, FlxG.keys will not be initialized yet before FlxGame's constructor has been called.



  • Ah you're right, that was the problem. Thanks a lot!

    The @:allow(flixel) at the top of FlxKeyManager confused me, so I just assumed it was something on Flixel's end.


  • administrators

    Whether or not you are allowed to access a field is checked at compile-time - if that was the issue, you would have gotten a compiler error, not a runtime error.


Log in to reply