Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Stage height and width in private const or variable

Explorer ,
Apr 20, 2013 Apr 20, 2013

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.

TOPICS
ActionScript
667
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 20, 2013 Apr 20, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 20, 2013 Apr 20, 2013

hi, it's line with this variable

private var _listH          :String = stage.stageHeight;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 20, 2013 Apr 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 20, 2013 Apr 20, 2013
LATEST

ps. I should add this information.

this is code for external swf.

if it's alone it works but if I load it to main swf it's not working.

and my only problem is this:

this is working

private const STAGE_HEIGHT:uint = 800;

and this not

private const STAGE_HEIGHT:uint = stage.stageHeight;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines