Я обновляю свои приложения с flex 3 до flex 4.5 и обнаружил ошибку. Это произошло, когда компонент был динамически добавлен в модуль. Коды, которые могут симулировать ошибку, были извлечены, как показано ниже.
TestError.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.events.ModuleEvent;
protected function ml_readyHandler(event:ModuleEvent):void
{
trace("Module finished loading");
(ml.child as TestErrorModuleInterface).testTracing();
}
]]>
</mx:Script>
<mx:ModuleLoader id="ml" url="TestErrorModule.swf" ready="ml_readyHandler(event)"/>
</mx:Application>
TestErrorModule.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" width="100%" height="100%"
implements="TestErrorModuleInterface">
<mx:Canvas id="_box">
<mx:Label text="HERE IS MY TEST MODULE" x="142" y="133"/>
</mx:Canvas>
<mx:Script>
<![CDATA[
public function testTracing():void
{
trace("This is a method in the Test Module");
var comp:TestErrorModuleComp = new TestErrorModuleComp();
_box.addChild(comp);
}
]]>
</mx:Script>
</mx:Module>
TestErrorModuleInterface.as
package {
public interface TestErrorModuleInterface {
function testTracing():void;
}
}
TestErrorModuleComp.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Label text="element" width="80" />
</mx:Canvas>
А вот подробная трассировка стека ошибок:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at TestErrorModule/testTracing()[F:\MyEclipse_9_0\workspace\ViSR_Interface_Flex4\flex_src\TestErrorModule.mxml:16]
at TestError/ml_readyHandler()[F:\MyEclipse_9_0\workspace\ViSR_Interface_Flex4\flex_src\TestError.mxml:12]
at TestError/__ml_ready()[F:\MyEclipse_9_0\workspace\ViSR_Interface_Flex4\flex_src\TestError.mxml:17]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[E:\dev\hero_private\frameworks\projects\framework\src\mx\core\UIComponent.as:13128]
at mx.modules::ModuleLoader/moduleReadyHandler()[E:\dev\hero_private\frameworks\projects\mx\src\mx\modules\ModuleLoader.as:465]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at ModuleInfoProxy/moduleEventHandler()[E:\dev\hero_private\frameworks\projects\framework\src\mx\modules\ModuleManager.as:1149]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at ModuleInfo/readyHandler()[E:\dev\hero_private\frameworks\projects\framework\src\mx\modules\ModuleManager.as:793]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::FlexModuleFactory/update()[E:\dev\hero_private\frameworks\projects\framework\src\mx\core\FlexModuleFactory.as:535]
at mx.core::FlexModuleFactory/docFrameHandler()[E:\dev\hero_private\frameworks\projects\framework\src\mx\core\FlexModuleFactory.as:681]
at mx.core::FlexModuleFactory/docFrameListener()[E:\dev\hero_private\frameworks\projects\framework\src\mx\core\FlexModuleFactory.as:131]
Большое спасибо!