如何将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>
答案 0 :(得分:7)
在设置x&amp;之前调用PopUpManager的centerPopUp函数。 y坐标将允许您更改警报窗口的位置。我已经更新了您提供的脚本,以便它确实适当地定位警报窗口:
<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>