4 Replies Latest reply on Jul 7, 2010 11:42 PM by IndPeter

    Module loading problem with datagrid

    IndPeter

      hello Friends,

       

      i am relatively new to flex.

       

      i am developing the module by extending the modulebase in AS.

       

      i wrote an actionscript to load this module into my main application. this code something like below,

      ..........................

      public function createFeatureByName(featureName:String):void{
                  getDefinitionbyName(featureName);           
              }
             
              public function getDefinitionbyName(featureName:String):Class{
                  addEventListener(ClassFoundEvent.FOUNDCLASS,returnClassNameListener);
                  try{
                      var classReference:Class=flash.utils.getDefinitionByName(featureName) as Class;
                      dispatchEvent(new ClassFoundEvent(ClassFoundEvent.FOUNDCLASS,classReference));
                      return classReference;
                  }catch(e:Error){
                      var moduleName:String=(featureName.split("."))[0];
                      for (var i:int=0;i<moduleArray.length;i++){
                          var moduleDatainfo:ModuleDataInfo=ModuleDataInfo(moduleArray[i]);
                          if(moduleDatainfo.moduleName == moduleName){ //we aleardy added the module so return only the class reference
                              var child:Object=moduleDatainfo.child;
                              if(child){
                                  try{
                                      var classReference1:Class=child.getDefinitionByName(featureName) as Class;
                                      dispatchEvent(new ClassFoundEvent(ClassFoundEvent.FOUNDCLASS,classReference1));
                                      return classReference1;
                                  }catch(e:Error){
                                      throw new Error("The given feature is not included in the Module or U missed the class Definition");
                                  }
                              }else{
                                  return null;
                              }
                          }
                      }               
                  }
                  loadModuel(featureName);
                  return null;
              }
             
              public function loadModuel(featureName:String):void{
                  if(featureName == null){
                      return;
                  }
                  dispatchEvent(new FlexEvent(FlexEvent.LOADING));
                  var moduleName:String=(featureName.split("."))[0];
                  var url:String="modules/"+moduleName+".swf";
                  var module:IModuleInfo;
                  module=ModuleManager.getModule(url);
                  trace("AmeModuleManager::loaded Module :"+moduleName)
                  moduleArray.push(new ModuleDataInfo(module,moduleName,featureName));
                  module.addEventListener(ModuleEvent.PROGRESS, moduleProgressHandler);
                  module.addEventListener(ModuleEvent.SETUP, moduleSetupHandler);
                  module.addEventListener(ModuleEvent.READY, moduleReadyHandler);
                  module.addEventListener(ModuleEvent.ERROR, moduleErrorHandler);
                  module.addEventListener(ModuleEvent.UNLOAD, moduleUnloadHandler);
                  module.load(applicationDomain);
              }
             
              public function unLoadModule():void{
                  for (var j:int=0;j<moduleArray.length;j++){
                      var moduleDataInfo:ModuleDataInfo=ModuleDataInfo(moduleArray[j]);
                      moduleDataInfo.module.removeEventListener(ModuleEvent.PROGRESS, moduleProgressHandler);
                      moduleDataInfo.module.removeEventListener(ModuleEvent.SETUP, moduleSetupHandler);
                      moduleDataInfo.module.removeEventListener(ModuleEvent.ERROR, moduleErrorHandler);
                      trace("AmeModuleManager::UnLoaded Module :"+moduleDataInfo.moduleName);
                      moduleDataInfo.module.unload();
                      moduleDataInfo.module.removeEventListener(ModuleEvent.UNLOAD, moduleUnloadHandler);
                  }
                  moduleArray=new Array();
              }
             
              protected function moduleProgressHandler(event:ModuleEvent):void
              {
                  dispatchEvent(event);
              }
             
              protected function moduleSetupHandler(event:ModuleEvent):void
              {
                  dispatchEvent(event);
              }
         
              protected function moduleErrorHandler(event:ModuleEvent):void
              {           
                  // unloadModule();
                  throw new Error("Unable to load requested module " + event.errorText );
                  dispatchEvent(event);
              }
             
              protected function moduleUnloadHandler(event:ModuleEvent):void
              {
                  dispatchEvent(event);
              }
         
              protected function moduleReadyHandler( event:ModuleEvent ):void
              {
                  var module:IModuleInfo=event.module; //newly created module;
                  var child:Object=module.factory.create() as Object;
                  if(child){
                      for(var k:int=0;k<moduleArray.length;k++){
                          var moduleDataInfo:ModuleDataInfo=ModuleDataInfo(moduleArray[k]);
                          if(moduleDataInfo.module == module){
                              moduleDataInfo.child=child;
                              var featurName:String=moduleDataInfo.featureName;
                              var moduleName:String=moduleDataInfo.moduleName;
                              break;
                          }
                      }
                      try{
                          var classReference:Class=child.getDefinitionByName(featurName) as Class;
                          dispatchEvent(new ClassFoundEvent(ClassFoundEvent.FOUNDCLASS,classReference));
                      }catch(error:Error){
                          throw new Error("The given feature is not included in the Module or U missed the class Definition");
                      }
                  }
              }

      ...................

      my basic idea is to create the class for the given url lets say "module1.swf" containig the mxml called "test1" . so if i pass the "module1.test1" for the createFeatureByName(....) , it will load the module to the main application and by dispatching the event ClassFoundEvent i am getting the created class in my main appliction. the event handler code something like

       

       

      private function getClassName(event:ClassFoundEvent):void{

      .................................

      .................
                      this.parentApplication.ameModuleManager.removeEventListener(ClassFoundEvent.FOUNDCLASS,ge tClassName);
                      mainScreen.removeAllChildren();
                      var dispObjClass:Class = event.classReference as Class;
                      trace(dispObjClass.toString())
                      var classFactory:ClassFactory = new ClassFactory(dispObjClass);
                      var component:* = classFactory.newInstance();
                      mainScreen.addChild(component);

      ...........................

      .............
                     
                  }

       

      in my module project some of the mxml containing the datagrid. if i a create the classes for those mxml files and loads by using the above code i am getting the below error...

       

      TypeError: Error #1007: Instantiation attempted on a non-constructor.
          at mx.controls.dataGridClasses::DataGridHeader/updateDisplayList()[C:\autobuild\3.2.0\framew orks\projects\framework\src\mx\controls\dataGridClasses\DataGridHeader.as:242]
          at mx.core::UIComponent/validateDisplayList()[C:\autobuild\3.2.0\frameworks\projects\framewo rk\src\mx\core\UIComponent.as:6351]
          at mx.managers::LayoutManager/validateClient()[C:\autobuild\3.2.0\frameworks\projects\framew ork\src\mx\managers\LayoutManager.as:880]
          at mx.core::UIComponent/validateNow()[C:\autobuild\3.2.0\frameworks\projects\framework\src\m x\core\UIComponent.as:5679]
          at mx.controls.dataGridClasses::DataGridBase/updateDisplayList()[C:\autobuild\3.2.0\framewor ks\projects\framework\src\mx\controls\dataGridClasses\DataGridBase.as:493]
          at mx.controls::DataGrid/updateDisplayList()[C:\autobuild\3.2.0\frameworks\projects\framewor k\src\mx\controls\DataGrid.as:1437]
          at mx.controls.listClasses::ListBase/validateDisplayList()[C:\autobuild\3.2.0\frameworks\pro jects\framework\src\mx\controls\listClasses\ListBase.as:3280]
          at mx.managers::LayoutManager/validateDisplayList()[C:\autobuild\3.2.0\frameworks\projects\f ramework\src\mx\managers\LayoutManager.as:622]
          at mx.managers::LayoutManager/doPhasedInstantiation()[C:\autobuild\3.2.0\frameworks\projects \framework\src\mx\managers\LayoutManager.as:677]
          at Function/http://adobe.com/AS3/2006/builtin::apply()

       

      by tracing down i understand that it miss some style propety....

       

      i dont know how i can overcome this ... am i missing to include something while i compiling the module project or the main appliction... i am breaking my head for a day.. can any one help me please