Wednesday, February 10, 2010

stage.width, stage.stageWidth, and loaderInfo.width

For any new Flasher comes the time of dealing with the stage and its properties. It is probably confusing for newcomers to distinguish between stage.width and stage.stageWidth, therefore this post. (the same logic follows for stage.height and stage.stageHeight)

stage.width is defined by the distance between the smallest and the largest x coordinate that its children reach at any certain point in time. If we imagine the stage as a balloon, the further we inflate it, the bigger the distance between its walls gets. Therefore, if you have tried to determine the width/height of the stage using the stage.width/stage.height properties, before anything has been put on the stage, the output must have always been 0.

stage.stageWidth, on the other hand, defines the width of the entire Flash window.

NOTE: Normally, one would assume that if the stage's scale mode is set to StageScaleMode.NO_SCALE, the stage.stageWidth will remain constant, no matter how much we resize the Flash window. Well, no .... stage.stageWidth changes all the time, regardless of what the documentation says.

If you want to get the value of the stage width, as defined in the project settings, or the SWF metadata, you should use loaderInfo.width

No comments: