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)

2 comments

  1. Glyn said:

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

  2. sarfaraz said:

    need ur help. i want to set width as i m loading an external file in a movieclip i want the size of stage to be movieclip size not the main width of the flash file.

    plz help
    sarf

Leave a Reply

Your email address will not be published. Required fields are marked *