Stage resizing and getting the right variable

怎甘沉沦 提交于 2019-12-05 20:46:01

First, it is important to know the difference between stage.stageHeight - stage.stageWidth and stage.height - stage.width

stage.stageHeight // The real height of the stage
stage.height // The height of the content on the stage

So, the reason you get 801 and 601 is because the height and width of the total content on the stage is 801 x 601.

Now, for the resizing issue. If you are displaying this in a webbrowser, then you can set the height and width of the movie. Set that to 800 and 600, not 100% and 100%. Now, your movie will always stay the same size, regardless of a user resizing their browser window.

If you do want to allow for height="100%" and width="100%" in your html markup, then you have a couple options.

  1. Make a MovieClip that will act as a pseudo-stage. It would be 800 x 600. Instead of adding things to the stage, add them to this MovieClip (say it is called myStage.) Now, all of the logic for keeping the objects inside the stage is instead applied to the myStage MovieClip.

  2. You can put constants in your AS3 code. For example:


 public const STAGE_WIDTH:int = 800;
 public const STAGE_HEIGHT:int = 600;

Now, you just use those values rather than your stage.stageHeight and stage.stageWidth values. Of course, you need to be sure to also include

stage.align = StageAlign.TOP_LEFT;  // or StageAlign.TOP
stage.scaleMode = StageScaleMode.NO_SCALE;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!