如何使用 Actionscript 可靠地捕获屏幕分辨率?
我有几个组件,它们的屏幕位置取决于浏览器所在监视器的分辨率。
登录框.x = (flash.system.Capability.screenResolutionX - 登录框.宽度)/2; 登录框.y = (flash.system.Capability.screenResolutionY - 登录框.高度)/2;
我遇到的问题是 flash.system.Capability 方法会拉取连接到计算机的主显示器的分辨率。在大多数情况下,这不是问题,但在我的一台计算机上,我有一个 1680x1050 和一个 1440x900。在工作中,我有一个 1920x1200 和一个 1680x1050,因此如果我在较小的显示器上的浏览器中打开页面,内容不会居中,并且我的工具面板完全位于屏幕右侧。
我已经尝试过一段javascript,无论是在html中还是通过php,但问题是,如果我使用httpRequest或urlLoader来获取html文件,我会得到html的源代码,如果我尝试php脚本,我得到一个正在尝试写入 cookie 的脚本块。如果在加载 Flash 站点之前没有访问过该页面,或者禁用了 cookie,则该页面永远不会被写入,我也无处可去。
我可以使用一种不依赖 cookie 的方法来检测浏览器实际所在的显示器的分辨率,而不仅仅是第一个显示器的分辨率吗?
I have several components who's screen position depends on the resolution of the monitor on which the browser lives.
loginBox.x = (flash.system.Capabilities.screenResolutionX - loginBox.width) / 2;
loginBox.y = (flash.system.Capabilities.screenResolutionY - loginBox.height) / 2;
The problem I'm encountering is that the flash.system.Capabilities method pulls the resolution of the primary monitor attached to the computer. In most situations this isn't a problem but on one of my computers, I have a 1680x1050 and a 1440x900. At work, I have a 1920x1200 and a 1680x1050, so if I open the page in a browser on the smaller monitor, things are not centered and my tools panel is completely off to the right of the screen.
I have a block of javascript that I've tried, both in html and through php but the problem is that if I use either httpRequest or urlLoader to grab the html file, I get the source of html and if I try the php script, I get a script block that is attempting to write a cookie. If that page has not been visited prior to loading the flash site, or if cookies are disabled, it never gets written and I'm nowhere.
Is there a method that I can use, that doesn't rely on cookies, to detect the resolution of the monitor that the browser is actually on, and not just the resolution of the first monitor?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不使用 stage.stageWidth 和 stage.stageHeight 来进行定位?
编辑:
好的,这是一个例子。
我正在考虑将此代码放置在 LoginBox 所在的容器中。
除非您的对象被添加到 DisplayList 中,否则 stage 属性是未定义的,因此您需要监听它何时被添加,然后定位登录框。
然后
另外,如果您将阶段scaleMode设置为noScale(可能是这种情况),如果您需要根据浏览器大小调整不断重新定位登录框,则需要侦听Event.RESIZE事件
Why don't you use stage.stageWidth and stage.stageHeight for positioning purposes?
EDIT:
Ok, here's an example.
I'm considering that you'll place this code inside the container where loginBox also resides.
The stage property is undefined unless your object is added to the DisplayList, so you need to listen for when it's added and then position the loginBox.
and then
Also, if you have stage scaleMode set to noScale (which maybe is the case), if you need to constantly reposition the loginBox based on browser resizing, you need to listen to an Event.RESIZE event
如果您尝试在 flash 和 javascript 之间进行通信,ExternalInterface是要走的路。无需编写 cookie,只需从 javascript 获取信息,然后通过回调将其发送到 flash。
If you're trying to communicate between flash and javascript, ExternalInterface is the way to go. Rather that writing a cookie, just grab the information from javascript, and send it to flash via a callback.