下面是创建自定义对话框的代码,我text
在两个标签中都设置了可绑定的,这样我就可以将字符串文本分配给标题和消息,而不必担心是否创建了相应的组件。
了解有关数据绑定和可绑定元数据标签的更多信息,以了解实际发生的情况。
自定义对话框.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300" backgroundImage="@Embed('y3jqqq5x.jpg')" backgroundSize="100%">
<mx:Script>
<![CDATA[
[Bindable]private var _title:String;
[Bindable]private var _message:String;
public function set title(value:String):void
{
_title = value;
}
public function set message(value:String):void
{
_message = value;
}
]]>
</mx:Script>
<mx:Label id="lblTitle" horizontalCenter="0" y="10" text="{_title}" fontSize="30"/>
<mx:Label id="lblMsg" width="250" height="160" horizontalCenter="0" y="100" text="{_message}" fontSize="14"/>
</mx:Canvas>
使用以下函数在您的 AS3 代码中创建自定义对话框,如下所示
private function showAlert():void
{
var popup:CustomDialog = new CustomDialog();
popup.title = "Title Goes Here";
popup.message = "Content goes here."
PopUpManager.addPopUp(popup, Application.application as DisplayObject, true);
PopUpManager.centerPopUp(popup);
}