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 usingFlxG.keys.preventDefaultKeys
reveals that I'm not allowed to access it, which seems to be becauseFlxKeyManager
is only given access permission within the flixel package. Certain fields such aspressed
andjustPressed
can be accessed outside of it because they have the(default, null)
, butpreventDefaultKeys
does not.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.
-
I get
Invalid field access
on the line where I try accesspreventDefaultKeys
. Everything is up to date.
-
Invalid field access
is a null reference error - perhaps you're trying to access it too early,FlxG.keys
will not be initialized yet beforeFlxGame
'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.
-
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.