在javascript中,有个confirm的提示框,actionscript可以改变Alert.show();的参数实现这个功能。代码如下
<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”absolute” backgroundGradientColors=”[#ffffff, #c0c0c0]”>
<mx:Script>
<![CDATA[
import mx.events.FlexEvent;
import mx.effects.Fade;
import mx.controls.Alert;
import mx.events.CloseEvent;
[Embed(source=’assets/exclamation.png’)]
private var confirmIcon:Class;
private function confirm():void {
// instantiate the Alert box
var a:Alert = Alert.show(”Are you sure you want to\nperform that action?”, “Confirmation”, Alert.YES|Alert.NO, this, confirmHandler, confirmIcon, Alert.NO);
//第一个参数是要显示的文本,第二个参数是窗口的标题,第三个参数是按纽,第四个参数是父窗体,第五个参数是关闭后要执行的动作函数,第六个参数是图标,第七个参数是默认的按纽
// modify the look of the Alert box
a.setStyle(”backgroundColor”, 0xffffff);
a.setStyle(”backgroundAlpha”, 0.50);
a.setStyle(”borderColor”, 0xffffff);
a.setStyle(”borderAlpha”, 0.75);
a.setStyle(”color”, 0×000000); // text color
}
private function confirmHandler(event:CloseEvent):void {
if (event.detail == Alert.YES) {
// what to do if user selected “yes”
result.text = “Yes”;
} else if (event.detail == Alert.NO) {
// what to do if user selected “no”
result.text = “No”;
}
}
]]>
</mx:Script>
<mx:Button x=”10″ y=”45″ label=”Confirm” click=”confirm();”/>
<mx:Label x=”10″ y=”19″ text=”Result:”/>
<mx:Label x=”63″ y=”19″ fontWeight=”bold” id=”result”/>
</mx:Application>