1 Reply Latest reply on Apr 18, 2011 7:50 PM by Flex harUI

    Modules Error/Bug and Spark

    bbehling

      Hello.

       

      In flex 4, I have a module that I can load successfully into an application. The problem is, when I try to cast an object or create an object of the type of my module, I get the bellow.

       

      Not sure where this problem is. If I change the code to use Flex 3.5, everything works find. If there bug with Flex 4, modules and spark?

       

      Thanks for any help

       

      Heres the code:


      Main.mxml ...

      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                     xmlns:s="library://ns.adobe.com/flex/spark"
                     xmlns:esri="http://www.esri.com/2008/ags"
                     xmlns:mx="library://ns.adobe.com/flex/mx"
                     minWidth="955" minHeight="600" applicationComplete="init();"
                      >
          <fx:Declarations>
              <!-- Place non-visual elements (e.g., services, value objects) here -->
          </fx:Declarations>
         
          <fx:Script>
             
              <![CDATA[
                  import com.gisworkshop.widgets.DataFrame.DataFrame;
                  import com.gisworkshop.widgets.DataFrame.IDataFrame;
                 
                  import mx.containers.Canvas;
                  import mx.core.IVisualElement;
                  import mx.events.ModuleEvent;
                  import mx.modules.IModuleInfo;
                  import mx.modules.ModuleLoader;
                  import mx.modules.ModuleManager;
                 
                  public var module:IModuleInfo;
                 
                 
                  public function init():void{           
                     
                      /*  Use the Module Manager to add the module to the app.
                          We have to use the addElement method of the main application so that the componants in the Module are seen.
                          This is a little different from the documentation because we are using spark and Flex 4 in the application. */
                     
                      module = ModuleManager.getModule("com/gisworkshop/widgets/DataFrame/DataFrame.swf");                
                                     
                      module.addEventListener(ModuleEvent.READY, modReadyHandler, false, 0, true);
                      module.addEventListener(ModuleEvent.ERROR, modErrorHandler, false, 0, true);
                      module.addEventListener(ModuleEvent.UNLOAD, modUnloadHandler, false, 0, true);
                     
                      module.load(null, null, null, moduleFactory);
                     
                  }
                 
                  private function modErrorHandler( moduleEvent:ModuleEvent ):void
                  {
                     
                     
                  }
                 
                  private function modReadyHandler( moduleEvent:ModuleEvent ):void
                  {
                      this.addElement(module.factory.create() as DataFrame);
                     
                      var obj:DataFrame;
                     
                                     
                  }
                 
                  private function modUnloadHandler( moduleEvent:ModuleEvent ):void
                  {
                     
                      //When we unload the module, remove it from the application
                      for (var i:int = 0; i < numElements; i++) {
                         
                          var objModule:Object = this.getElementAt(i);
                         
                          //the object we want to remove has the property "cvsDataFrame"
                          if (objModule.hasOwnProperty("cvsDataFrame")){
                              this.removeElementAt(i);
                          }  
                         
                      }
                     
                      /*When we unload the module, we remove all the event listeners and anything referenced to the module object.
                        Re-define the event listeners for the module object */
                     
                      module = ModuleManager.getModule("com/gisworkshop/widgets/DataFrame/DataFrame.swf");                
                     
                      module.addEventListener(ModuleEvent.READY, modReadyHandler, false, 0, true);
                      module.addEventListener(ModuleEvent.ERROR, modErrorHandler, false, 0, true);
                      module.addEventListener(ModuleEvent.UNLOAD, modUnloadHandler, false, 0, true);
                     
                      module.load(null, null, null, moduleFactory);
                     
                  }

       

                  private function loadModule():void{
                     
                      module.unload();
         
                  }
                 
              ]]>
             
          </fx:Script>
         
          <esri:Map id="mainMap">
             
              <esri:ArcGISDynamicMapServiceLayer id="baseMap" url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"/>
          </esri:Map>
         
          <mx:Button label="Load" click="loadModule();"/>
                    
      </s:Application>

       

      DataFrame Module...

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Module xmlns:fx="http://ns.adobe.com/mxml/2009"
                 xmlns:s="library://ns.adobe.com/flex/spark"
                 xmlns:mx="library://ns.adobe.com/flex/mx" layout="absolute" width="400" height="300" implements="com.gisworkshop.widgets.DataFrame.IDataFrame"
                
                 >
          <fx:Declarations>
              <!-- Place non-visual elements (e.g., services, value objects) here -->
          </fx:Declarations>
          <fx:Script>
             
              <![CDATA[
                 
                  import com.esri.ags.Map;
                 
                  [Bindable]
                  private var _Map:Map;
                 
                  public function setMap(map:Map):void{
                     
                      _Map = map;
                     
                  }
                 
                  public function zoom():void{
                     
                      _Map.zoomIn();
                     
                  }
                 
              ]]>
             
          </fx:Script>

       

          <mx:Canvas id="cvsDataFrame" width="100" height="50" top="90" left="0" >
              <mx:Button label="Zoom" left="0" top="0" click="zoom();"/>
          </mx:Canvas>
         
      </mx:Module>

       

       

      IDataFrame Interface...

       

       

      package com.gisworkshop.widgets.DataFrame
      {
          import com.esri.ags.Map;

       

          public interface IDataFrame
          {
              function setMap(_Map:Map):void;
              //function
          }
      }

       

      ArgumentError: Error #2004: One of the parameters is invalid.
          at flash.display::Graphics/drawRoundRect()
          at spark.primitives::Rect/draw()[E:\dev\4.x\frameworks\projects\spark\src\spark\primitives\R ect.as:459]
          at spark.primitives.supportClasses::StrokedElement/updateDisplayList()[E:\dev\4.x\frameworks \projects\spark\src\spark\primitives\supportClasses\StrokedElement.as:143]
          at spark.primitives.supportClasses::GraphicElement/http://www.adobe.com/2006/flex/mx/internal::doUpdateDisplayList()[E:\dev\4.x\frameworks\pr ojects\spark\src\spark\primitives\supportClasses\GraphicElement.as:3893]
          at spark.primitives.supportClasses::GraphicElement/validateDisplayList()[E:\dev\4.x\framewor ks\projects\spark\src\spark\primitives\supportClasses\GraphicElement.as:3877]
          at spark.components::Group/updateDisplayList()[E:\dev\4.x\frameworks\projects\spark\src\spar k\components\Group.as:956]
          at spark.skins::SparkSkin/updateDisplayList()[E:\dev\4.x\frameworks\projects\spark\src\spark \skins\SparkSkin.as:191]
          at mx.skins.spark::SparkSkinForHalo/updateDisplayList()[E:\dev\4.x\frameworks\projects\spark skins\src\mx\skins\spark\SparkSkinForHalo.as:118]
          at mx.skins.spark::ButtonSkin/updateDisplayList()[E:\dev\4.x\frameworks\projects\sparkskins\ src\mx\skins\spark\ButtonSkin.mxml:66]
          at mx.core::UIComponent/validateDisplayList()[E:\dev\4.x\frameworks\projects\framework\src\m x\core\UIComponent.as:8709]
          at mx.managers::LayoutManager/validateClient()[E:\dev\4.x\frameworks\projects\framework\src\ mx\managers\LayoutManager.as:932]
          at mx.core::UIComponent/validateNow()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\U IComponent.as:7792]
          at mx.controls::Button/http://www.adobe.com/2006/flex/mx/internal::viewSkinForPhase()[E:\dev\4.x\frameworks\proje cts\framework\src\mx\controls\Button.as:1985]
          at mx.controls::Button/http://www.adobe.com/2006/flex/mx/internal::viewSkin()[E:\dev\4.x\frameworks\projects\fram ework\src\mx\controls\Button.as:1885]
          at mx.controls::Button/commitProperties()[E:\dev\4.x\frameworks\projects\framework\src\mx\co ntrols\Button.as:1631]
          at mx.core::UIComponent/validateProperties()[E:\dev\4.x\frameworks\projects\framework\src\mx \core\UIComponent.as:7933]
          at mx.managers::LayoutManager/validateProperties()[E:\dev\4.x\frameworks\projects\framework\ src\mx\managers\LayoutManager.as:572]
          at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.x\frameworks\projects\framewo rk\src\mx\managers\LayoutManager.as:700]
          at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.x\frameworks\projects \framework\src\mx\managers\LayoutManager.as:1072]