当我尝试使用超过 2 个模块加载器时,就会出现我的问题。我的第一个问题是当我尝试使用多个 1 时。您可以在下面看到我的解决方法。我对 Modules 还有些陌生,所以如果我在这里遗漏了一些明显的东西,我不会感到惊讶。让我丧命的是它有时如何工作,但有时却没有?
错误:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at ModuleInfo/completeHandler()[C:\autobuild\3.x\frameworks\projects\framework\src\mx\modules\ModuleManager.as:717]
我的应用程序:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600">
<mx:Script>
<![CDATA[
import mx.core.Application;
import mx.events.ModuleEvent;
import mx.managers.PopUpManager;
import mx.modules.IModuleInfo;
import mx.modules.ModuleManager;
private var popUpManager:PopUpManager;
private var podXml:XML;
private var moduleIsReady:Boolean;
private function getSwf():String
{
return "location/SimpleModule.swf";
}
private function onModuleUnload(moduleEvent:ModuleEvent):void
{
// Had to release in order to get 2 to work, now it breaks on 3
var info:IModuleInfo = ModuleManager.getModule(getSwf());
info.release();
info = null;
trace("module unloaded");
}
private function onModuleReady(moduleEvent:ModuleEvent):void
{
// Module loaded
// moduleIsReady = true; //used as a flag for child to know when the module itself is ready
//var ichild:MyInterface = module.child as MyInterface
//if (module.child != null)
//{
// ichild.doStuff();
//}
}
]]>
</mx:Script>
<mx:Canvas>
<mx:ModuleLoader url="{getSwf()}" id="module" ready="onModuleReady(event)" unload="onModuleUnload(event)" x="50" y="50" width="100" height="100"/>
<mx:ModuleLoader url="{getSwf()}" id="module1" ready="onModuleReady(event)" unload="onModuleUnload(event)" x="50" y="250" width="100" height="100"/>
<mx:ModuleLoader url="{getSwf()}" id="module2" ready="onModuleReady(event)" unload="onModuleUnload(event)" x="50" y="450" width="100" height="100"/>
</mx:Canvas>
</mx:Application>
我的模块:
<?xml version="1.0" encoding="utf-8"?>
<mx:Module layout="absolute" xmlns:mx="http://www.adobe.com/2006/mxml"
width="100%" height="100%"
backgroundColor="0xFF0000">
</mx:Module>
谢谢。