使用接口调用多个动态Module的同一方法
2009-05-14 11:28
459 查看
问题:
主页面有一个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;
}
}
主页面有一个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;
}
}
相关文章推荐
- 使用微信js接口的方法 ,以调用相机为例
- Python接口(1):使用Python调用C/C++的种种方法
- struts2如何动态调用action的方法以及使用json插件范围json格式的javascript对象
- 第三章Struts2 Action中动态方法调用、通配符的使用
- Struts2学习笔记(七):动态方法调用和使用通配符定义action
- iOS银联支付原理及接口调用方法(参考2.0.0使用指南)
- struts2中动态方法调用和使用通配符定义Action
- C#反射动态调用dll中的方法及使用QuartZ.net实现作业调度
- Java中使用HttpRequest调用RESTfull的DELETE方法接口提示:How to fix HTTP method DELETE doesn't support output
- 使用 HttpWebRequest的psot方式传参数调用接口方法
- struts2中动态方法调用和使用通配符定义Action
- 使用反射-动态创建对象及调用对象方法
- 3.6.3: 配置Action---使用Action的动态方法调用
- 使用接口的方式调用远程服务 ------ 利用动态调用服务,实现.net下类似Dubbo的玩法。
- Unity中使用UGUI制作Prefab后,调用Instantiate动态生成Button无法点击的解决方法
- dll动态链接库之用类写配置文件和调用判断方法接口的实现中遇到的若干问题
- Struts 2读书笔记-----使用Action的动态方法调用
- [c#美味] 使用反射动态创建实例并调用方法
- 使用反射构造对象实例并动态调用方法
- struts中3种情况通配符的使用方法 及 动态方法调用