3

如何将 Flex Alert 框放置在某个 x,y 位置,以下代码不起作用,Alert 框始终位于屏幕中央。

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" >

    <fx:Script>
        <![CDATA[
            import mx.controls.Alert;
            protected function showAlert(event:MouseEvent):void
            {

                myAlert = Alert.show('alert', 'Error - ');

                myAlert.x = 40; 
                myAlert.y = 50;
//              myAlert.move(-400,-500);  // doesn't work either
            }
            private var myAlert:Alert;
        ]]>
    </fx:Script>
    <s:Button label="click me" click="showAlert(event)" />
</s:Application>
4

1 回答 1

7

在设置 x 和 y 坐标之前调用 PopUpManager 的 centerPopUp 函数将允许您更改警报窗口的位置。我已经更新了您提供的脚本,以便它正确定位警报窗口:

<fx:Script>
    <![CDATA[
        import mx.controls.Alert;
        import mx.managers.PopUpManager;

        private var myAlert:Alert;

        protected function showAlert(event:MouseEvent):void
        {
            myAlert = Alert.show('alert', 'Error - ');
            PopUpManager.centerPopUp(myAlert);
            myAlert.x = 40; 
            myAlert.y = 50;
        }

    ]]>
</fx:Script>
于 2013-05-01T19:12:04.133 回答