Flex 用接口把值传递给子界面 .

 

 

二、程序源代码

<Interface1.as>

package myInterface
{
	public interface Interface1
	{
		function func1(par_str:String):String;
	}
}


 

<moduel.mxml>

<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:fx="http://ns.adobe.com/mxml/2009" 
		   xmlns:s="library://ns.adobe.com/flex/spark" 
		   xmlns:mx="library://ns.adobe.com/flex/mx" 
		   layout="absolute" width="290" height="195"
		    verticalAlign="middle" horizontalAlign="center"
		    implements="myInterface.Interface1">
	<fx:Script>
		<![CDATA[
			import myInterface.Interface1;
			/**
			 * 实现接口函数实体
			 * */
			public function func1(par_str:String):String{
			txt_value.text=par_str;
			return "我是Fnuc1的返回值";
			}
		]]>
	</fx:Script>
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
	</fx:Declarations>
	<s:Label text="显示从主画面传入函数参数" width="202" fontSize="14" x="47" y="49"/>
	<s:TextInput id="txt_value" width="174" enabled="false" x="47" y="87"/>
</mx:Module>


<textInterface.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" 
			   minWidth="955" minHeight="600" xmlns:ns1="*"
			    creationComplete="init()">

	<fx:Script>
		<![CDATA[
			import myInterface.Interface1;
			
			/**
			 * 初始化
			 * */
			private function init():void{
			
				//加载子界面
				moduleLoader1.url="moduel.swf";
			}
			
			
			/**
			 * 通过接口调用子界面1中的函数func1
			 * */
			protected function button1_clickHandler(event:MouseEvent):void
			{
				//定义接口变量
				var ichild:Interface1=moduleLoader1.child as myInterface.Interface1;
				if(ichild!=null)
				{
				  //调用接口函数
				  txtResult1.text=ichild.func1(txtData1.text);
				}
			}
		]]>
	</fx:Script>

	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
	</fx:Declarations>
	<mx:Panel x="333" y="92" width="381" height="244" title="子界面">
		
		<mx:ModuleLoader width="377" height="211" id="moduleLoader1" y="0"/>
	</mx:Panel>
	
	
	<s:Panel x="46" y="92" width="262" height="245" title="通过接口调用子界面中的函数">
		<s:TextInput x="71" y="47" id="txtData1"/>
		<s:TextInput x="71" y="134" id="txtResult1"/>
		<s:Button x="71" y="91" id="but1" label="调用函数" click="button1_clickHandler(event)"/>
		<s:Label x="71" y="27" text="测试接口函数:func1" fontFamily="中易宋体"/>
		<s:Label x="10" y="47" text="函数参数" height="24" verticalAlign="middle" fontFamily="中易宋体"/>
		<s:Label x="3" y="138" text="函数返回值" height="18" fontFamily="中易宋体" verticalAlign="middle"/>
	</s:Panel>
</s:Application>


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值