這時候的錯誤是我在handleModuleReady功能得到錯誤:的Flex「類型強制」鑄造接口
[Fault] exception, information=TypeError: Error #1034: Type Coercion failed:
can not convert [email protected] 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」正確? – Glenn 2009-07-16 04:13:32
它在標記中「實現IModuleInterface」。有什麼額外的需要做的是正確的? –
calvinf
2009-07-16 07:10:53