加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 01:00:54 所属栏目:百科 来源:网络整理
导读:? ? 二、程序源代码 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

?

?

二、程序源代码

<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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读