舞台调整大小和获得正确的变量 [英] Stage resizing and getting the right variable

查看:123
本文介绍了舞台调整大小和获得正确的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Flash应用程序(AS3),我想在舞台的大小和使用屏幕的,所以我的对象(用户控件)不能到外面去。但是,当我使用:

  stage.stageWidth;
stage.stageHeight;
 

是我得到的值实际上不是我想要的。他们给我的舞台大小,但如果我调整窗口的大小,数字改变。现在,在一个HTML页面,我不认为这会事,因为用户不能调整它。不过,我想它是不是依赖于窗口大小更加牢固。我也尝试使用:

  stage.width;
stage.height;
 

然而,这些给了我801和601的时候,比我的实际舞台大小。当我调整窗口这些价值并没有改变,但它们是一个更大的。

所以我的问题是,如何才能得到舞台大小,无论调整窗口永远是800×600的? (也许隐藏在这个问题就是:为什么我会收到801和601吗?我能阻止人们调整窗口的大小?)唷!谢谢!

解决方案

首先,重要的是要知道的 stage.stageHeight的区别 - stage.stageWidth和stage.height - stage.width

  stage.stageHeight //舞台的真正高度
舞台上的内容的stage.height //高度
 

所以,原因你获得801和601是因为在舞台上的总含量的高度和宽度是801 x 601

现在,对于调整大小的问题。如果您在网页浏览器显示这一点,那么你可以设置电影的高度和宽度。设置,为800和600,而不是100%和100%。现在,你的电影将永远留在用户调整他们的浏​​览器窗口的大小相同,而不管。

如果你想允许在你的HTML标记高度=100%和宽度=100%,那么你有一对夫妇的选择。

  1. 请一个视频剪辑将充当伪阶段。这将是800 X 600而不是添加的东西在舞台上,将其添加到该影片剪辑(比如它被称为myStage)。现在,所有的逻辑为保持对象级内部而不是加到myStage影片剪辑。

  2. 您可以把常量在AS3 code。例如:


 公共常量STAGE_WIDTH:INT = 800;
 公共常量STAGE_HEIGHT:INT = 600;
 

现在,你只需要使用这些值,而不是你的stage.stageHeight和stage.stageWidth值。当然,你需要确保包括

  stage.align = StageAlign.TOP_LEFT; //或StageAlign.TOP
在Stage.scaleMode = StageScaleMode.NO_SCALE时;
 

In my Flash Application (AS3), I want to get the stage size and use that so my objects (which the user controls) can't go outside of the screen. However, when I use:

stage.stageWidth;
stage.stageHeight;

The values I get aren't actually what I want. They give me the stage size, but if I resize the window, the numbers change as well. Now, in a html page, I don't think that will matter, because the user can't resize it... however, I'd like for it to be more solid than relying on the window size. I also tried to use:

stage.width;
stage.height;

However, those gave me "801" and "601", one greater than my actual stage size. Those values did not change when I resized the window, but they were one greater.

So my question is, how can I get the stage size, regardless of resizing the window to always be 800 by 600? (And perhaps hidden in that question is, "Why do I get 801 and 601?" and "Can I stop people from resizing the window?") Phew! Thank you!

解决方案

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;

这篇关于舞台调整大小和获得正确的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆