AS3:获取浏览器窗口的大小?浏览器、大小、窗口

2023-09-08 12:20:27 作者:狂放

我可以在获取浏览器窗口的大小,AS3?

Can I get the obtain the size of the browser window in AS3?

我发现最好的方法是让大小的JavaScript,并将其发送到Flash作为一个Flash变量。这种方法的一个限制是,它不给当前的大小,如果窗口大小改变

The best method I've found is to get the size with Javascript and send it to Flash as a FlashVar. One limitation of this method is that it doesn't give the current size if the window is resized.

有没有一种纯粹的闪存办法做到这一点?

Is there a pure Flash way to do this?

推荐答案

这取决于如果你想你的swf设置为全屏,或简单地获取窗口尺寸用于其他目的。

It depends if you are trying to set your swf to fullscreen, or simply obtain window dimensions for some other purpose.

如果你正在做的全屏,你需要设置你的一个StageScaleMode 以NO_SCALE,并嵌入您的Flash对象插入一个div,有其高度,并设置为100%宽度参数。为了解决大小调整,您的Flash项目需要一个调整大小事件侦听器(适用于舞台),和所有的显示对象需要到调整大小的监听器做出反应。一旦您的SWF被调整得当,就可以了,前面已经提到的,使用stage.stageHeight / stageWidth从内部获取精确的尺寸。

If you are doing fullscreen, you need to set your stageScaleMode to NO_SCALE, and embed your flash object into a div that has its height and width parameters set to 100%. To deal with resizing, your flash project needs a resize event listener (applied to the stage), and all display objects need to respond to that resize listener. Once your swf is resizing properly, you can, as already noted, use stage.stageHeight / stageWidth to retrieve exact dimensions internally.

如果,在另一方面,你只是想获取窗口dimesions,你需要使用 ExternalInterface的进行的JavaScript调用。 jQuery有快速获取屏幕dimentions一些很好的工具。然后发送的数据回闪它只是一个问题。请记住,JavaScript有resize事件,以及,那你可以用它来强制闪光状态更改。

If, on the other hand, you just want to obtain the dimesions of the window, you will need to use ExternalInterface to make a javascript call. jQuery has some nice tools for quickly obtaining screen dimentions. Then its just a matter of sending that data back into flash. Remember that javascript has a resize event, as well, and that you can use it to force state changes in flash.

您是在最初的一段序列正确的 - 在负载发送FlashVars的,但屏幕大小的变化做出反应,你需要利用这些技术中的一种

You're correct in the initial piece of the sequence - sending flashvars in on load, but to respond to screen size changes, you will need to apply one of these techniques.

好运气