Flex PopUpManager 窗体间参数传递

来源:互联网 发布:贺伟解说 知乎 编辑:程序博客网 时间:2024/06/05 11:26
//TestPopForm 主窗体(Application)<?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600"><mx:Script><![CDATA[import mx.binding.utils.BindingUtils;import mx.managers.PopUpManager;//打开窗口 并将参数传过去private function newPopForm():void{var popup:PopForm=new PopForm();popup.text=tInput.text;popup.callback=closeHandler;PopUpManager.addPopUp(popup,this);PopUpManager.centerPopUp(popup);}//关闭打开窗口时处理private function closeHandler(text:String):void{tInput.text=text;}]]></mx:Script><mx:TextInput id="tInput" name="mytext" x="87" y="67"/><mx:Button x="295" y="67" label="点击弹出窗口" click="newPopForm()"/></mx:Application>//PopForm 弹出窗体(组件)<?xml version="1.0" encoding="utf-8"?><mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300" backgroundColor="#E3EEFB" initialize="init()"><mx:Script><![CDATA[import mx.controls.TextInput;import mx.managers.PopUpManager;public var text:String;public var callback:Function;//定义关闭窗口后调用的函数//初始化函数private function init():void{textInput.text=text;}//点击确认,关闭弹出窗口,将弹出窗口参数传递给父窗窗口private function onSubmit():void{if(callback!=null){callback(textInput.text);}PopUpManager.removePopUp(this);} ]]></mx:Script><mx:TextInput id="textInput" x="92" y="51"/><mx:Button x="187" y="171" label="关闭弹出窗口" click="onSubmit()"/></mx:Canvas>