stage.width vs stage.stageWidth

I was trying to figure out how to access the width of the stage as it is when you make a document in Flash (defaults to that lovable 550px wide). Not only that, but I was trying to do it from an external AS document (ie. an AS file that wasn’t the document class); long story short about that — any external AS file that extends MovieClip or Sprite is ultimately just a far-away subclass of the DisplayObject class; therefore,

stage.width

or

stage.stageWidth

works in external AS docs AFTER the class has been added to the stage (that’s the gotcha!).

OKAY, so: 

stage.width

(or height) gives you the width of everything currently on the stage. If you’ve got nothing on the stage,

stage.width

returns 0. It was incredibly frustrating.

Moral of the story:

trace(this.stage.width); // width of everything currently on the stage (could be 0)
this.stage.stageWidth; // width of the stage (defaults to 550)

One Response

  1. Glyn:

    You rock dude!!!! Just getting back into ActionScript after a few years and never knew the! Cheers mate :)

Leave a Reply