【发布时间】:2010-11-11 04:51:17
【问题描述】:
这是我在 handleModuleReady 函数中遇到的错误:
[Fault] exception, information=TypeError: Error #1034: Type Coercion failed:
can not convert MyModule@39b8479 to IModuleInterface.
我有一个应用程序设置,并且我创建了要在运行时加载的模块以减小文件大小(因为大多数用户只需要其中一个模块)。
<!-- maker.mxml -->
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns="*"
layout="absolute"
creationComplete="init(event)">
<mx:Style source="css/maker.css" />
<mx:Script>
<![CDATA[
//Modules
import mx.events.ModuleEvent;
import mx.modules.ModuleLoader;
import mx.modules.ModuleManager;
import mx.modules.IModuleInfo;
private var info:IModuleInfo;
...
private function init(e:Event):void {
info = ModuleManager.getModule("MyModule.swf");
info.addEventListener("ready", handleModuleReady);
info.addEventListener("error", handleModuleError);
info.load(ApplicationDomain.currentDomain);
}
private function handleModuleReady(moduleEvent:ModuleEvent):void {
var ichild:IModuleInterface = IModuleInterface(moduleEvent.target.factory.create());
if (ichild != null) {
//call class functions here via ichild object
}
else {
trace("Something has gone wrong.");
}
}
...
</mx:Script>
...
我已经创建了 IModuleInterface 类 (IModuleInterface.as),并且 MyModule.mxml 文件编译没有问题,但是尽管尝试了各种潜在的解决方案,例如通过 ModuleLoader、ModuleManager、最近设置了 applicationDomain。
如果您知道如何解决此问题,请告诉我。互联网的其余部分没有。相信我,我已经看过了。
如果相关,界面看起来像这样。
//IModuleInterface.as
package
{
public interface IModuleInterface {
function getSomeClass():Class;
function getSomeArray():Array;
function getSomeInt():int;
}
}
【问题讨论】:
-
愚蠢的问题,但我认为 MyModule 正确实现了“IModuleInterface”?
-
它在
标签中“实现了 IModuleInterface”。是否需要做一些额外的事情才能正确?
标签: apache-flex interface module