2014-03-26 53 views
0

我有一个高大的Flex应用程序,它使用Alert.show()显示错误/警告消息。当错误消息集中在屏幕上时,这会产生问题,但当屏幕位于极端滚动位置(顶部或底部)时不可见。有什么方法可以在用户的​​可查看页面的中心显示警报。我试过以下,但没有奏效。如何在flex中居中对齐Alert.show()

var errorMsg:Alert = Alert.show("Error message"); 
PopUpManager.centerPopUp(errorMsg); 

在此先感谢。

回答

1

这是我的问题的解决方案,我用JavaScript调用来实现这一点。

var viewPoint:Number = ExternalInterface.call("eval", "window.pageYOffset"); 
var browserHeight:Number = ExternalInterface.call("eval", "window.innerHeight"); 
//the following calculation finds the center y coordinate in user's viewable page. 
var viewableY : Number = ((browserHeight/2)+viewPoint-50); 
var alert : Alert = Alert.show("Error Msg"); 
PopUpManager.centerPopUp(alert); 
alert.move(400,viewableY); 

我希望这可以帮助别人......

4

Alert通常以您在参数中提供的父母为中心。

在以下静态方法父参数中使用(FlexGlobal.topLevelApplication as parent)作为参数。

Alert.show(text:String = "", title:String = "", flags:uint = 0x4, parent:Sprite = null, closeHandler:Function = null, iconClass:Class = null, defaultButtonFlag:uint = 0x4, moduleFactory:IFlexModuleFactory = null); 
+0

嘿宙斯,感谢您的回复,但我的主要应用高度高一点,所以上述的解决方案并没有帮助我。但是,通过使用JavaScript调用,我现在可以在中心显示警报。再次感谢您的回复。 – Ramesh