这个是外部对话框 保存为MyTitleWindow.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" width="200" height="150"
title="请在此输入您的名字!" fontWeight="normal" fontSize="12" showCloseButton="true" close="PopUpManager.removePopUp(this);">
<mx:TextInput x="10" y="10" id="myTextInput"/>
<mx:Button x="36" y="74" label="确定" id="myButton"
click="closeTitleWindow(event);"/>
<mx:Script>
<![CDATA[
import mx.managers.PopUpManager;
import mx.controls.Text;
// 定义一个变量来获取对主应用程序的引用
public var myObj:Object;
// 该方法用来关闭弹出的TitleWindow 容器.
private function closeTitleWindow(event:MouseEvent):void {
myObj.myLabel.text = "您输入的是:" + myTextInput.text;
myObj.myLabel.setStyle("color",String(cp.selectedColor))
PopUpManager.removePopUp(this);
}
private function close(evt:MouseEvent):void{
PopUpManager.removePopUp(this);
}
]]>
</mx:Script>
<mx:Button x="96" y="74" label="close" click="close(event);"/>
<mx:ColorPicker x="10" y="44" id="cp" selectedColor="#F30A0A"/>
</mx:TitleWindow>
这个是主程序,取名随便啦,比如a1.mxml ,这里要引用刚刚那个"MyTitleWindow"类
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" fontSize="12" xmlns:ns1="*" layout="absolute">
<mx:Script>
<![CDATA[
import flash.events.*;
import mx.managers.PopUpManager;
import mx.containers.TitleWindow;
// 响应按钮单击事件,弹出myTitleWindow对话框
private function openWindow(event:MouseEvent):void {
// 使用PopUpManager.createPopUp方法弹出myTitleWindow
var aTitleWindow:MyTitleWindow=MyTitleWindow(PopUpManager.createPopUp(this,MyTitleWindow, true));
PopUpManager.centerPopUp(aTitleWindow); //居中
// 注意这里为自定义组件的myObj属性赋值以引用当前MXML文档
aTitleWindow.myObj = this;
}
]]>
</mx:Script>
<mx:Button label="打开对话框" click="openWindow(event);" x="404" y="24"/>
<mx:Label id="myLabel" text="wait..." width="200" x="375" y="110" fontWeight="bold" fontSize="18" color="#06C9F3"/>
</mx:Application>
执行结果如下:
如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛