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

编程入门 行业动态 更新时间:2024-10-24 12:31:25
本文介绍了AS3:获取浏览器窗口大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

我发现的最好方法是使用 Javascript 获取大小并将其作为 FlashVar 发送到 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.

有没有纯粹的 Flash 方式来做到这一点?

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 对象嵌入到高度和宽度参数设置为 100% 的 div 中.为了处理调整大小,您的 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.

另一方面,如果您只想获取窗口的尺寸,则需要使用 ExternalInterface 进行 javascript 调用.jQuery 有一些很好的工具可以快速获取屏幕尺寸.然后它只是将该数据发送回闪存的问题.请记住,javascript 也有一个 resize 事件,您可以使用它来强制 Flash 中的状态更改.

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.

祝你好运

更多推荐

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

本文发布于:2023-11-23 15:47:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622008.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:浏览器   大小   窗口

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!