`
fatherican
  • 浏览: 49158 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

Flex PopUpManager 弹出窗口居中

 
阅读更多

今天看到窗口居中弹出,我便想到了Alert,既然Alert每次都能居中弹出,为什么我们自定义的窗口不能居中弹出呢,所以,我查看了下Alert的

show方法,放到我的代码中,果然也能居中弹出了,不论布局是如何设计的,下面是主要代码:


//自定义弹出的窗口大小
var title:TitleWindow=new TitleWindow();
title.width = 300;
title.height = 300;

var parent:Sprite = this;
if (!parent)
{
var sm:ISystemManager=ISystemManager(Application.application.systemManager);
if (sm.useSWFBridge())
parent=Sprite(sm.getSandboxRoot());
else
parent=Sprite(Application.application);
}

PopUpManager.addPopUp(title, parent);
//居中显示
PopUpManager.centerPopUp(title);


具体是为什么,不懂.



下面的是我转载的,比较好理解。

转载于:http://webair.iteye.com/blog/1042065

有些情况下 Flex自带的使弹出窗口居中的方法并不能满足我们的要求,例如Flex应用有多个层次时

所以我们有时必须手动设置弹出窗口的位置:

Actionscript代码收藏代码
  1. PopUpManager.addPopUp(window,this,true);
  2. PopUpManager.centerPopUp(window);
  3. //下面两行是关键的,如果有多个几层弹出窗口的话使用上面的方法没法居中,必须手动设置窗口位置,
  4. //当然这个只是居中于屏幕中间,如果你是想居中于上一级弹出窗口的中间的话,那就不能添加下面两行代码了
  5. window.x=Application.application.stage.stageWidth/2-window.width/2;
  6. window.y=Application.application.stage.stageHeight/2-window.height/2;
  7. //Flex4中需要下面方法
  8. window.x=FlexGlobals.topLevelApplication.stage.stageWidth/2-window.width/2;
  9. window.y=FlexGlobals.topLevelApplication.stage.stageHeight/2-window.height/2;
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics