调整阶段大小并获取正确的变量
在我的 Flash 应用程序 (AS3) 中,我想要获取舞台大小并使用它,以便我的对象(用户控制的)无法超出屏幕。但是,当我使用:
stage.stageWidth;
stage.stageHeight;
我得到的值实际上并不是我想要的。他们给我舞台大小,但如果我调整窗口大小,数字也会改变。现在,在 html 页面中,我认为这并不重要,因为用户无法调整它的大小......但是,我希望它比依赖窗口大小更可靠。我也尝试使用:
stage.width;
stage.height;
但是,这些给了我“801”和“601”,比我的实际舞台尺寸大一号。当我调整窗口大小时,这些值没有改变,但它们更大了。
所以我的问题是,无论将窗口大小调整为始终为 800 x 600,如何获得舞台大小? (也许隐藏在这个问题中的是,“为什么我会得到 801 和 601?”和“我可以阻止人们调整窗口大小吗?”)唷!谢谢你!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,了解stage.stageHeight - stage.stageWidth和stage.height - stage.width之间的区别很重要。
所以,你得到801和601的原因是因为总的高度和宽度舞台上的内容是801 x 601。
现在,关于调整大小的问题。如果您在网络浏览器中显示此内容,则可以设置影片的高度和宽度。将其设置为 800 和 600,而不是 100% 和 100%。现在,无论用户如何调整浏览器窗口的大小,您的电影将始终保持相同的大小。
如果您确实想在 html 标记中允许 height="100%" 和 width="100%",那么您有几个选择。
制作一个充当伪舞台的影片剪辑。它将是 800 x 600。不要将内容添加到舞台,而是将它们添加到此 MovieClip(假设它称为 myStage)。现在,将对象保留在舞台内的所有逻辑都应用于 myStage MovieClip。< /p>
您可以将常量放入 AS3 代码中。例如:
现在,您只需使用这些值,而不是 stage.stageHeight 和 stage.stageWidth 值。当然,您还需要确保包括
First, it is important to know the difference between
stage.stageHeight - stage.stageWidth and stage.height - stage.width
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.
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.
You can put constants in your AS3 code. For example:
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