DirectX Video Tutorials Who Moved My Cheese! I try to be Haw
Dec 06

I am working on an ActionScript 3.0 module in my day job, and although I am new to ActionScript, I rarely touch the documentation (yeah yeah, I know I should do it more often =) ), most of the time it works, may be because I was on Java before.

Last day, I needed to find out the stage’s height somewhere, so I just typed

stage.h

and thanks to intelli-sense, it quickly told me that it was

stage.height

i was looking for. But something strange happened and i was not getting the value i expected. After a couple of hours of hair pulling, it dawned on me that I should be using

stage.stageHeight

instead of

stage.height

to get stage’s height.

I can’t say whether Adobe/Macromedia’s decision to use

stage.stageHeight

and

stage.stageWidth

instead of

stage.height

and

stage.width

was right, but the property name is not abundantly clear in what it is going to return.

Technorati Tags: , ,

written by ishaq


4 Responses to “ActionScript: stage.height does *not* return stage’s height”

  1. 1. Idetrorce Says:

    very interesting, but I don’t agree with you
    Idetrorce

  2. 2. ishaq Says:

    exactly what is it that you don’t agree with?

  3. 3. Lasse Adolphsen Says:

    Hi,

    stage.stageHeight returns the height of the actual stage (i.e. the area you see when running your movie), whereas stage.height returns the height of the CONTENT on the stage.
    Say, you’ve set the dimensions of the stage to 500×500 and added a movieclip with the dimensions 100×100 anywhere on the stage, you would get the following:

    trace(stage.height); // Outputs “100″
    trace(stage.stageHeight); // Outputs “500″

    If you have several movieclips, buttons, etc. on your stage, stage.height gives you the total height of all content on stage.

    Hope this makes sense.

  4. 4. ishaq Says:

    I agree with you till on that stage.height returns *actual* height.

    But I don’t agree with the rest, I think (I didn’t dig deeper into it that’s why I only *think* so) that stage.stageHeight returns the height of the *viewable* area (i.e. the height and width at which the movie is being displayed).

    I say so because in the module mentioned above, I was trying to make my Sprite scale (and thereby incorporate more content into it) upon resizing the browser window. Using stage.stageHeight and stage.stageWidth worked for rescaling (i.e. calculating the size of viewable area and resizing the sprite accordingly).

    I may be wrong, let me know if it is so.

Leave a Reply