如果我理解正確你,這聽起來像:
- 您在HTML頁面中
- 中心在某些情況下有一個小的Flex應用程序,你想創建一個HTML彈出(新瀏覽器彈出窗口)。
- 該彈出窗口應該位於HTML頁面的中心。
如果這是正確的,則不需要使用localToGlobal或globalToLocal;你只是在尋找瀏覽器的視口邊界。這是我目前正在使用放置在相關項目到瀏覽器邊界的方法(這一切的是JavaScript的):
function getBrowserBounds()
{
var size = [0, 0];
if (typeof window.innerWidth != "undefined") {
size = [window.innerWidth, window.innerHeight];
}
else if (typeof document.documentElement != "undefined" && typeof document.documentElement.clientWidth != "undefined" && document.documentElement.clientWidth != 0) {
size = [document.documentElement.clientWidth, document.documentElement.clientHeight];
}
else {
size = [document.getElementsByTagName("body")[0].clientWidth, document.getElementsByTagName("body")[0].clientHeight];
}
var bounds = null;
if (navigator.userAgent.indexOf("MSIE") != -1) // Internet Explorer
bounds = [window.screenLeft, window.screenTop, size[0], size[1]];
else
bounds = [window.screenX, window.screenY, size[0], size[1]];
var width = bounds[0] + (bounds[2]/2);
var height = bounds[1] + (bounds[3]/2);
return bounds;
}
返回瀏覽器的可視區域的範圍。從那裏,你可以創建一個在瀏覽器內中心的彈出窗口,只要在瀏覽器是筆記本/桌面屏幕範圍內,使用此:
function centerPopup(windowHeight, windowWidth, windowName, windowUri)
{
var bounds = getBrowserBounds();
var centerWidth = bounds[0] + ((bounds[2] - windowWidth)/2);
var centerHeight = bounds[1] + ((bounds[3] - windowHeight)/2);
newWindow = window.open(windowUri, windowName, 'resizable=0,width=' + windowWidth +
',height=' + windowHeight +
',left=' + centerWidth +
',top=' + centerHeight);
newWindow.focus();
return newWindow.name;
}
讓我知道是否可行。
最佳, 蘭斯
是彈出菜單將在Flex或HTML?如果它是flex,並且flex已經在html的中心,爲什麼你需要swf的x/y值?你不能只使用localtoglobal函數? – Amarghosh 2010-02-18 06:58:08