使用接口调用多个动态Module的同一方法

问题:

        主页面有一个ModuleLoader,通过以改变URL加载不同的Module。要在页面点击一button调用实例里面的方法。

解决:

        使所有Module实现一个定义了要调用方法的接口。

主页面代码:
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical">
<mx:Script>
<![CDATA[
private function displayModule( moduleUrl:String ):void
{
 var url:String = moduleLoader.url;
 if( url == moduleUrl ) return;
 if( url != null)
  moduleLoader.unloadModule();
 moduleLoader.url = moduleUrl;
}
private function showHandler():void
{
 displayModule( "ContactList.swf");
}
private function enterHandler():void
{
 displayModule( "ContactEntry.swf");
}

private function test():void
{
 var myModule:Imodule = moduleLoader.child as Imodule;
 myModule.test();
}
]]>

 

</mx:Script>
<mx:Panel title="Contacts:" width="100%" height="100%" horizontalAlign="center" verticalAlign="middle">
<mx:ModuleLoader id="moduleLoader" width="100%" height="100%"  url="ContactList.swf"/>
<mx:HBox width="100%">
<mx:Button label="textModule" click="showHandler();" />
<mx:Button label="checkModule"
click="enterHandler();" />
 <mx:Button label="调用模块内部的方法"  click="test()"/>
</mx:HBox>
</mx:Panel>
</mx:Application>

 

模块ContactEntry:

<mx:Module
xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" implements="Imodule">


<mx:Script>
<![CDATA[
import mx.controls.Alert;
public function test():void
{
  lab.text=txt.text;
}
]]>
</mx:Script>

 <mx:TextInput id="txt" text="12312312"/>
 <mx:Label id="lab" text=""/>
 
 <mx:Button id="btn" label="Button" click="test()"/>
</mx:Module>

模块ContactList:

<mx:Module
xmlns:mx="http://www.adobe.com/2006/mxml"
width="100%" height="100%" implements="Imodule">
<mx:Script>

 <![CDATA[
import mx.controls.Alert;
public function test():void
{
   lab.text=rbg.selection.label;
}
 ]]>
</mx:Script>
 <mx:RadioButtonGroup  id="rbg"/>
 <mx:RadioButton label="Button 1" groupName="rbg"/>
 <mx:RadioButton label="Button 2" groupName="rbg"/>
 <mx:Label id="lab" text=""/>
 <mx:Button id="btn" label="Button" click="test()"/>
</mx:Module>

接口

package
{
 public interface Imodule
 {
  function test():void;
 }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值