• Flex父子窗体相互调用


    Flex父子窗体相互调用


    1、设计思路

    (1)子窗体调用父窗体的方法

    (2)子窗体做了改动后,返回父窗体,父窗体调用子窗体函数


    2、设计源代码

    (1)父窗体

    ParentWindow.mxml:

    <?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"
    			   width="100%" height="100%">
    	<s:layout>
    		<s:BasicLayout/>
    	</s:layout>
    	<fx:Declarations>
    		<!-- 将非可视元素(比如服务、值对象)放在此处 -->
    	</fx:Declarations>
    	
    	<fx:Script>
    		<![CDATA[
    			import mx.collections.ArrayCollection;
    			import mx.controls.Alert;
    			import mx.managers.PopUpManager;
    			
    			[Bindable]
    			//表格数据源绑定
    			private var grid:ArrayCollection = new ArrayCollection([
    				{number:"2014010101",name:"张散",sex:"男",age:"23"},
    				{number:"2014010102",name:"李思",sex:"女",age:"22"},
    				{number:"2014010101",name:"吴王",sex:"男",age:"21"},
    				{number:"2014010101",name:"赵柳",sex:"女",age:"20"},
    				{number:"2014010101",name:"游华",sex:"男",age:"22"},
    				{number:"2014010101",name:"祝思",sex:"女",age:"18"},
    				{number:"2014010101",name:"周礼",sex:"男",age:"19"},
    				{number:"2014010101",name:"华捷",sex:"女",age:"20"},
    				{number:"2014010101",name:"刘亮",sex:"男",age:"22"},
    				{number:"2014010101",name:"沈雪",sex:"女",age:"21"}
    			]);
    
    			/*改动事件函数*/
    			protected function updateHandler(event:MouseEvent):void
    			{
    				//新建子窗口对象
    				var childWindow:ChildWindow = new ChildWindow();
    				//将子窗口加入到PopUpManager中
    				PopUpManager.addPopUp(childWindow,this,true);
    				//向子窗口传递參数
    				childWindow.age = "23";
    				//子窗口调用父窗口函数
    				childWindow.callBack = this.myFunction;
    				//子窗口居中弹出
    				PopUpManager.centerPopUp(childWindow);
    			}
    			
    			/*刷新函数*/
    			public function myFunction(you:String):void 
    			{  
    				Alert.show(you+"Hello");  
    			} 
    
    		]]>
    	</fx:Script>
    	<mx:VBox width="100%" height="100%" paddingBottom="10" paddingLeft="10" paddingRight="10" paddingTop="10">
    		<mx:DataGrid id="dataGrid" dataProvider="{grid}" rowCount="{grid.length + 1}" width="100%" 
    					 verticalAlign="middle" textAlign="center">
    			<mx:columns>
    				<mx:DataGridColumn headerText="学号" dataField="number"/>
    				<mx:DataGridColumn headerText="姓名" dataField="name"/>
    				<mx:DataGridColumn headerText="性别" dataField="sex"/>
    				<mx:DataGridColumn headerText="年龄" dataField="age"/>
    			</mx:columns>
    		</mx:DataGrid>
    		<mx:HBox width="100%" horizontalAlign="center" verticalAlign="middle">
    			<s:Button label="改动" click="updateHandler(event)"/>
    		</mx:HBox>
    	</mx:VBox>
    </s:Application>
    


    (2)子窗体

    ChildWindow.mxml:

    <?xml version="1.0" encoding="utf-8"?>
    <s:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009" 
    			   xmlns:s="library://ns.adobe.com/flex/spark" 
    			   xmlns:mx="library://ns.adobe.com/flex/mx" width="300" height="220"
    			   close="closeHandler(event)" title="改动窗体">
    	<s:layout>
    		<s:BasicLayout/>
    	</s:layout>
    	<fx:Script>
    		<![CDATA[
    			import mx.events.CloseEvent;
    			import mx.managers.PopUpManager;
    			
    			//回调函数
    			public var callBack:Function;
    			
    			public var age:String = "";
    
    			/*关闭事件函数*/
    			protected function closeHandler(event:CloseEvent):void
    			{
    				PopUpManager.removePopUp(this);
    			}
    
    			/*改动button事件函数*/
    			protected function updateHandler(event:MouseEvent):void
    			{
    				stuAge.text = age;
    			}
    			
                /*取消button事件函数*/
    			protected function cancelHandler(event:MouseEvent):void
    			{
    				number.text = "";
    				stuName.text = "";
    				PopUpManager.removePopUp(this);
    				if(isPopUp)
    				{
    					callBack.call(parent);
    				}
    			}
    		]]>
    	</fx:Script>
    	<fx:Declarations>
    		<!-- 将非可视元素(比如服务、值对象)放在此处 -->
    	</fx:Declarations>
    	
    	<mx:VBox width="100%" height="100%">
    		<mx:Form>
    			<mx:FormItem label="学号:">
    				<s:TextInput id="number" width="200" maxChars="10"/>
    			</mx:FormItem>
    			<mx:FormItem label="姓名:">
    				<s:TextInput id="stuName" width="200" maxChars="10"/>
    			</mx:FormItem>
    			<mx:FormItem label="性别:">
    				<mx:HBox width="100%">
    					<mx:RadioButtonGroup id="sex"/>
    					<s:RadioButton groupName="sex" label="男" selected="true"/>
    					<s:RadioButton groupName="sex" label="女"/>
    				</mx:HBox>
    			</mx:FormItem>
    			<mx:FormItem label="年龄:">
    				<s:TextInput id="stuAge" width="200" maxChars="2"/>
    			</mx:FormItem>
    			<mx:FormItem>
    				<mx:HBox width="100%">
    					<s:Button label="改动" click="updateHandler(event)"/>
    					<s:Label width="42"/>
    					<s:Button label="取消" click="cancelHandler(event)"/>
    				</mx:HBox>
    			</mx:FormItem>
    		</mx:Form>
    	</mx:VBox>
    </s:TitleWindow>
    

    3、设计结果

    (1)初始化时



    (2)单击改动button


  • 相关阅读:
    大端序与小端序
    中断分类
    PHP开发框架[国内框架]
    PHP开发框架[流行度排名]
    ecshop 后台分页功能
    Windows下phpStudy中的Apache无法启动的排查方法
    Windows里配置Apache2.2+PHP5.3+mod_fcgid运行高效的FastCGI模式
    Apache多虚拟主机多版本PHP(5.2+5.3+5.4)共存运行配置全过程
    让 Node.js 支持 ES6 的语法
    微信小程序请求wx.request数据,渲染到页面
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/3749446.html
Copyright © 2020-2023  润新知