Get width and get height for positioning

this is a simple question.
but all im trying to do is get the width and height of the screen so i can set the location of either buttons [which im asking about in another post ;)], text, characters etc etc.

but have been doing soemthing like this, which is from the learn section of OPENFL. but it runs into errors saying ‘invalid field access : stageWidth’

textField.x = (stage.stageWidth - textField.width) / 2;
textField.y = (stage.stageHeight - textField.height) / 2;


You could try using
Lib.current.stage.stageWidth & Lib.current.stage.stageHeight
instead :slight_smile:

1 Like

well. what do you know. that worked :wink:

as you can tell im still getting to know HAXE & OPENFL. we still have not been out to dinner yet, but we are getting there :wink:


In your document class, you are already on the stage, so stage is not null. However, in other objects, stage will be null until you add it to the display list. In some cases, using the static Lib.current reference is good (Actuate uses this) but in most projects, I recommend following the standard flow, try not to reference the stage from objects not on the display list

1 Like

cool spot. good to know. ill try and keep all this piled in my head :wink: