我可以在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:获取浏览器窗口大小?
发布评论