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.preventDefaultKeysand giving it a value of
[FlxAndroidKey.BACK]but unfortunately the app crashes on launch. Testing it on neko using
FlxG.keys.preventDefaultKeysreveals that I'm not allowed to access it, which seems to be because
FlxKeyManageris only given access permission within the flixel package. Certain fields such as
justPressedcan be accessed outside of it because they have the
(default, null), but
Is this a bug or am I just going about this the wrong way?
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.
Invalid field accesson the line where I try access
preventDefaultKeys. Everything is up to date.
Invalid field accessis a null reference error - perhaps you're trying to access it too early,
FlxG.keyswill not be initialized yet before
FlxGame's constructor has been called.
Ah you're right, that was the problem. Thanks a lot!
@:allow(flixel)at the top of FlxKeyManager confused me, so I just assumed it was something on Flixel's end.
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.