我有一个MXML组件“PresentationWindow”,这是为了简洁起见,只需:
<fx:Script>
//... functions here will be explained below
</fx:Script>
<s:Window>
<mx:Canvas id="presentationCanvas" width="100%" height="100%">
<mx:Button label="Test" width="100" height="25" left="0" top="100" />
</mx:Canvas>
</s:Window>
我正试图得到一个
MX.Controls.警报
如果用户试图在窗口中退出,则在窗口上居中显示
StageDisplayState.Full_屏幕_Interactive
. 我很容易让警报出现,停止/允许退出工作的功能,但警报窗口本身不会正确居中。
当前,在cmd/ctrl+q上,我将窗口退出全屏模式,防止窗口关闭事件,并显示警告(如果我将其保留在全屏模式下,则会出现相同的错误行为):
Alert.show("Are you sure you want to quit with a presentation in progress?",
"Quit?", (Alert.YES | Alert.NO), presentationCanvas, alertHandler);
我试过以“this”为中心,在NativeWindow对象上,现在在占整个窗口的PresentationCanvas上;但是,在所有情况下,我都会
this glorious centering effect
(无论按钮是否在画布对象中)。
我还尝试将事件侦听器添加到窗口
事件.全屏
,因此无论您是进入还是退出全屏,如果存在警报窗口,请使用
PopupManager.CenterPopup()。
试图使警报居中。
没有什么能把那个警报窗口移到我窗口的中间。
有什么想法吗?(以下是完整的actionscript,我当前尝试居中失败…)
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.managers.PopUpManager;
import mx.events.CloseEvent;
private var alert:Alert;
private function windowInit():void {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP;
stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
nativeWindow.addEventListener(Event.CLOSING, preventCloseIfFullScreen);
}
protected function preventCloseIfFullScreen(e:Event):void {
if (stage.displayState == StageDisplayState.FULL_SCREEN_INTERACTIVE) {
e.preventDefault();
stage.addEventListener(Event.FULLSCREEN, adjustAfterFullScreen);
alert = Alert.show("Are you sure you want to quit with a presentation in progress?", "Quit?", (Alert.YES | Alert.NO), presentationCanvas, alertHandler);
//stage.displayState = StageDisplayState.NORMAL;
}
}
protected function adjustAfterFullScreen(e:FullScreenEvent):void {
if (alert) {
Alert.show("hi");
PopUpManager.centerPopUp(alert);
}
}
protected function alertHandler(e:CloseEvent):void {
if (e.detail == Alert.YES) {
NativeApplication.nativeApplication.exit();
}
else {
stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
}
}
]]>
</fx:Script>