8 Replies Latest reply on Dec 11, 2008 10:37 PM by cesaregb

    Communication between modules

    cesaregb Level 1
      Hi all,

      Im trying to load a module within other module and i want to communicate them ... this is possible ?
      I've been trying it with the parentApplication and i didn't have result neither with the a = mymove.child ... lo call a function .. i call the function but i cant pass any parameter. and sent me an error.

      anyone know how can i do this ... any of this make sense ?

      I hope someone can help me on this ...

      Best Regards
      Cesar
        • 1. Communication between modules
          Gregory Lafrance Level 6
          See this LiveDocs link on communicating between modules, as well as on communicating between main app and modules.

          Consider carefully the section on avoiding creating tightly coupled dependencies between apps and modules.

          Passing Data
          • 2. Re: Communication between modules
            *gsb* Level 1
            Also check out the Mate framework.
            You may find that their event mapping might well serve your communication needs.

            • 3. Re: Communication between modules
              cesaregb Level 1
              Sorry, i've read that info and try to do it ...

              this is the code:

              <!-- ********* Module of Accionistas ***** -->
              <mx:Canvas label="Accionistas" width="100%" height="100%">
              <mx:ModuleLoader url="modules/utilities/Accionistas.swf"
              id="accionistasModule" ready="setProveeId()"
              right="10" top="10" left="10" bottom="20"/>
              </mx:Canvas>

              this is the function in the parent

              public function setProveeId():void{
              // mdle = Accionistas(accionistasModule.child as Accionistas);
              mdle = (accionistasModule.child as Accionistas);
              mdle.uploadId("1");
              }

              and this would be the function on the child

              public function uploadId(id:String=""):void
              {
              vProveedor = id;
              Alert.show(String(id));
              //Alert.show(parentApplication.PATH);
              }

              and this is the error that i keep receiving:
              Cannot access a property or method of a null object reference

              then it is called the child function but i didn't send the "1" in this case... the parameter ...

              do you know why this is happening both are <modules.... so maybe that have something to do .. cuz all those examples are with application module ...

              i'll be glad if any of you know something about this...
              • 4. Re: Communication between modules
                cesaregb Level 1
                ahh one module is parent of the other
                • 5. Re: Communication between modules
                  cesaregb Level 1
                  i've try it with and application and it works but when i load that application with the SWFLoader

                  i keep retriving the same error

                  when i assing the module i retrive it as null

                  mdle = (accionistasModule.child as Accionistas);
                  mdle.uploadId("u");
                  and when i call the uploadId() function i got the
                  TypeError: Error #1009: Cannot access a property or method of a null object reference.

                  error

                  any of you know why could be happening this to me ??
                  • 6. Re: Communication between modules
                    Level 7
                    i've try it with and application and it works but when i load that application
                    with the SWFLoader

                    i keep retriving the same error

                    when i assing the module i retrive it as null

                    mdle = (accionistasModule.child as Accionistas);
                    mdle.uploadId("u");
                    and when i call the uploadId() function i got the
                    TypeError: Error #1009: Cannot access a property or method of a null object
                    reference.

                    error

                    any of you know why could be happening this to me ??

                    • 7. Re: Communication between modules
                      Gregory Lafrance Level 6
                      Your descriptions are very fragmented, thus it is hard to follow what you are saying, or to understand the problem.

                      Can you post simplified yet complete code?
                      • 8. Re: Communication between modules
                        cesaregb Level 1
                        Sorry,

                        The problem is that i need load some module inside other module and that one (the parent load it in the application)

                        mi code is like this:

                        <mx:Application ...
                        <mx:ModuleLoader url="modules/formProveedores.swf" left="100" top="65" right="30" bottom="30"/>
                        ...mx:Applicatoin>

                        this module formProveedores is kind of big ..

                        <mx:Module xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" width="100%"
                        height="100%" xmlns:components="components.*" xmlns:utilities="modules.utilities.*"
                        creationComplete="initApp()">

                        <mx:Style source="../styles/styles.css" />
                        <mx:Script source="../AS/ASProveedores.as" />
                        ...
                        <!-- ********* Module of Accionistas ***** -->
                        <mx:Canvas label="Accionistas" width="100%" height="100%">
                        <mx:ModuleLoader url="modules/Accionistas.swf"
                        id="accionistasModule" ready="setProveeId()"
                        right="10" top="10" left="10" bottom="20"/>
                        </mx:Canvas>
                        <!-- ********* End Module of Accionistas ***** -->

                        ..
                        </mx:Module>
                        /* the AS of this module is like this:
                        // ActionScript file
                        import AS.ObjProveedor;

                        import modules.Accionistas;

                        import mx.controls.Alert;
                        import mx.modules.IModuleInfo;
                        import mx.modules.ModuleManager;
                        import mx.rpc.events.FaultEvent;
                        import mx.rpc.events.ResultEvent;

                        public var assetModule:IModuleInfo;
                        public var sm:Object;
                        private const _strDomain:String = new String(" http://localhost/proveedores/");
                        private const _strUploadScript:String = new String(_strDomain + "upload.php");
                        [Bindable]
                        public var myProvee:ObjProveedor = new ObjProveedor();
                        public var mdle:Accionistas;

                        public function faultHandle(e:FaultEvent):void{
                        Alert.show(String(e));
                        }
                        public function resultHandler(e:ResultEvent):void{}

                        public function setProveeId():void{
                        //accionistasModule.child.uploadId("a");
                        mdle = accionistasModule.child as modules.Accionistas;
                        mdle.uploadId("u");
                        }

                        private function initApp():void {
                        var Obj:Object = new Object();
                        Obj.bring = "cedula";
                        Security.allowDomain(_strDomain);
                        ProveedoresDyn.addEventListener(ResultEvent.RESULT, bringCedula);
                        ProveedoresDyn.url = _strDomain + "bringSessions.php"
                        ProveedoresDyn.send(Obj);
                        }

                        private function bringCedula(e:ResultEvent):void
                        {
                        myProvee.cedula = int(String(e.result.num_cedula)) + 1;
                        ProveedoresDyn.removeEventListener(ResultEvent.RESULT, bringCedula);
                        }

                        private function searchImages(id_o:String):void{
                        // this is to update the list of the documents uploaded
                        }

                        and the accionistas module is kind of big too but is like this:
                        <mx:Module xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" width="100%" height="100%"
                        creationComplete="init(event)">
                        <mx:Script source="../AS/ASAccionistas.as" />
                        ...

                        ..
                        </mx:Module>
                        this AS file has a function wich is:
                        public function uploadId(id:String=""):void
                        {
                        vProveedor = id;
                        Alert.show("---"+String(id));
                        //Alert.show(parentApplication.PATH);
                        }

                        and all the other things i think they doesnt matter in this problem if you need info about it i;ll pot them...


                        and when i run it when the module parent is an application it works it call the function in the child the problem comes when i add it to the parent parent Application when i run the principal application ... it keep sending me this error:

                        TypeError: Error #1009: Cannot access a property or method of a null object reference.
                        at modules::formProveedores/setProveeId()[C:\Documents and Settings\cesar\My Documents\Flex Builder 3\Proveedores\src\AS\ASProveedores.as:28]
                        at modules::formProveedores/__accionistasModule_ready()[C:\Documents and Settings\cesar\My Documents\Flex Builder 3\Proveedores\src\modules\formProveedores.mxml:83]
                        at flash.events::EventDispatcher/dispatchEventFunction()
                        at flash.events::EventDispatcher/dispatchEvent()
                        at mx.core::UIComponent/dispatchEvent()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\co re\UIComponent.as:9051]
                        at mx.modules::ModuleLoader/moduleReadyHandler()[E:\dev\3.0.x\frameworks\projects\framework\ src\mx\modules\ModuleLoader.as:335]
                        at flash.events::EventDispatcher/dispatchEventFunction()
                        at flash.events::EventDispatcher/dispatchEvent()
                        at ModuleInfoProxy/moduleEventHandler()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\mo dules\ModuleManager.as:1027]
                        at flash.events::EventDispatcher/dispatchEventFunction()
                        at flash.events::EventDispatcher/dispatchEvent()
                        at ModuleInfo/readyHandler()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\modules\Modul eManager.as:706]
                        at flash.events::EventDispatcher/dispatchEventFunction()
                        at flash.events::EventDispatcher/dispatchEvent()
                        at mx.core::FlexModuleFactory/update()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\cor e\FlexModuleFactory.as:325]
                        at mx.core::FlexModuleFactory/docFrameHandler()[E:\dev\3.0.x\frameworks\projects\framework\s rc\mx\core\FlexModuleFactory.as:413]


                        is kind of big sorry i hope really hope this can help you to help me im almos done with this i really need to do it this way ... of if you can advice me about some way to do it more simply .. I'll be glad

                        Regards
                        Cesar