Skip to main content
Inspiring
April 20, 2013
Question

Stage height and width in private const or variable

  • April 20, 2013
  • 1 reply
  • 697 views

Hello, everyone I've got problem with this code.

I need stage size in const or variable because of some resize reasons.

ok so, code below works but it's static and I need dynamicaly get stage size.

private const LIST_HEIGHT          :uint = 800;

private const LIST_WIDTH            :uint = 1200;

with(_mask)

{

graphics.beginFill(0);

graphics.drawrect(0, 0, LIST_WIDTH, LIST_HEIGHT);

graphics.endFill();

}

and if I change constants to this:

private const LIST_HEIGHT          :uint = stage.stageHeight;

private const LIST_WIDTH           :uint = stage.stageWidth;

it's not work

also this not work

private var _listH          :uint = stage.stageHeight;

private var _listW         :uint = stage.stageWidth;

and this:

private var _listH          :String = stage.stageHeight;

private var _listW         :String = stage.stageWidth;

not work means that I get this error

TypeError: Error #1009: Cannot access a property or method of a null object reference.

          at com.filebrowser::FilesList()[/Users/Peter/Desktop/projectfl/projectfl beta 0.6/as3/com/filebrowser/FilesList.as:14]

          at flash.display::Sprite/constructChildren()

          at flash.display::Sprite()

          at flash.display::MovieClip()

          at com.filebrowser::FileBrowser()[/Users/Peter/Desktop/projectfl/projectfl beta 0.6/as3/com/filebrowser/FileBrowser.as:51]

Thanks in advance for all replies, all help is very appreciated.

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
April 20, 2013

Line 14 of your FileList.as file is where the error occurs.  What is that line?

Inspiring
April 20, 2013

hi, it's line with this variable

private var _listH          :String = stage.stageHeight;

Ned Murphy
Legend
April 20, 2013

Try tracing the stage just before that line and see if it is coming up null. 

If it is, then you need to hold off executing the code until after things have settled following setup.  You can use an ADDED_TO_STAGE listener to call a function that executes the code that needs to wait for the stage to exist.