5 Replies Latest reply on Oct 2, 2012 6:30 AM by david_kenneth_coleman

    Error loading module with MX and Spark components in FLEX 4

    hloops23 Level 1

      I need to be able to instantiate components dynamically, so I have to load  SWF modules based on a config XML file. The modules are based on mx:module and have a conbination of spark and mx components. I am using a variation of the below code to load the modules:

       

       

      module = ModuleManager.getModule(component.@url.toString());

      module.addEventListener(ModuleEvent.READY,moduleReady);

      module.addEventListener(ModuleEvent.ERROR,moduleError);

      module.load();

       

       

       

      private  function moduleReady(event:ModuleEvent):void

      {

       

       

      var modelInfo:IModuleInfo = event.currentTarget as IModuleInfo;

      var myInstance:IVisualElement = modelInfo.factory.create() as IVisualElement;

      this.addElement(myInstance);

      }

       

       

      I then get the following error when I wrap the content of the module in a BorderContainer

       

       

       

      ypeError: Error #1009: Cannot access a property or method of a null object reference.

      at mx.core::UIComponent/getStyle()[E:\dev\4.0.0\frameworks\projects\framework\src\ mx\core\UIComponent.as:10372]

      at mx.core::UIComponent/getConstraintValue()[E:\dev\4.0.0\frameworks\projects\fram ework\src\mx\core\UIComponent.as:8612]

      at mx.core::UIComponent/get horizontalCenter()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UICom ponent.as:8730]

       

      when I remove the border container, I get the following error:

      ArgumentError: Error #2004: One of the parameters is invalid.

      at flash.display::Graphics/drawRect()

      at mx.graphics::RectangularDropShadow/drawShadow()[E:\dev\4.0.0\frameworks\project s\framework\src\mx\graphics\RectangularDropShadow.as:575]

      at cobalt.skins::BorderSkin/updateDisplayList()[E:\dev\4.0.0\samples\themes\cobalt \src\cobalt\skins\BorderSkin.mxml:113]

      at mx.core::UIComponent/validateDisplayList()[E:\dev\4.0.0\frameworks\projects\fra mework\src\mx\core\UIComponent.as:8531]

      at mx.managers::LayoutManager/validateDisplayList()[E:\dev\4.0.0\frameworks\projec ts\framework\src\mx\managers\LayoutManager.as:663]:

       

       

      When I add the module explicitely as component to another MXML file, it loads just fine with no errors.

       

      This is a trimmed version of my module:

       

       

      <mx:Module  width="100%" height="100%"

          xmlns:fx="http://ns.adobe.com/mxml/2009"

      xmlns:s="library://ns.adobe.com/flex/spark"

      xmlns:mx="library://ns.adobe.com/flex/mx" >

       

       

       

      <s:BorderContainer  width="100%" height="100%">

       

      <mx:Image bottom="10" right="10" id="companyLogo" source="{source}" />

      <mx:Image y="{this.height /2+12}" click="Hide('tableOfContent')" left="2" id="forward"/>

      <mx:Image y="{this.height /2-13}" left="2" click="Show('tableOfContent')" id="back" />

      <s:Group id="mapTypes" left="60" top="10" alpha="0.9" click="mapTypes_clickHandler(event)">

      <s:layout>

      <s:ButtonBarHorizontalLayout gap="2" />

      </s:layout>

           ..//// other components that get loaded dynamically...

      </s:Group>

      <components:SystemMgr id="pSysMgr"/>

      </s:BorderContainer>

       

      </mx:Module>

       

      I just need to be able to load these modules dynamically.

       

      Thanks