What is Invalid Field Access?

1,460 views
Skip to first unread message

Andrew B

unread,
Feb 10, 2014, 11:42:34 PM2/10/14
to haxef...@googlegroups.com
I've got a bit of code that looks like this:

var mx:Int = Std.int(FlxG.mouse.screenX / player.sprite.width);

I get an invalid field access error when accessing the width property: Invalid field access : get_width

I've tried just hardcoding player.sprite.width to a number like so:
var mx:Int = Std.int(FlxG.mouse.screenX / 32);

and all it seems to do is defer this error until later when I access the x property of the sprite:
Invalid field access : x

I'm not sure why this is happening, the sprite is definitely instantiated as I can see it onscreen - wondering if anyone can shed light on what this error message means?

Samuel Batista

unread,
Feb 11, 2014, 10:08:46 AM2/11/14
to haxef...@googlegroups.com
Seems like player.sprite is null in this example. It might be a valid sprite that was added to an FlxState (which explains why you can see it), but that reference is not valid.

Andrew B

unread,
Feb 11, 2014, 11:08:20 PM2/11/14
to haxef...@googlegroups.com
Ah, seems I had used the var keyword again inside a function reducing the variable's scope so this was indeed the issue - thank you!
Reply all
Reply to author
Forward
0 new messages