4 Replies Latest reply on Jan 27, 2011 12:39 AM by Flex_Crazy

    Module Loader Problems In Flex....

    Flex_Crazy

      Everytime i load a Module from a tree menu in the Application, at time of exiting the module the main application needs to refreshed if not the next module loaded doesn't function properly (ComboBoxes don't get populated, Buttons don't execute the desired function...etc)

        • 1. Re: Module Loader Problems In Flex....
          Gaurav J Adobe Employee

          Which version of Flex SDK ?

           

          Post the code that you are using to load/unload modules.

           

          -Gaurav

          http://www.gauravj.com/blog

          • 2. Re: Module Loader Problems In Flex....
            Flex_Crazy Level 1

            Flex 3.2 SDK is the version that i'm using.....

             

             

            Flex Code:

             

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application tabEnabled="false" tabChildren="true" xmlns:mx="http://www.adobe.com/2006/mxml" initialize="init()" 
                applicationComplete="registerGlobalKeyHandler()"  layout="absolute" width="100%" height="100%"
                xmlns:model="com.citizen.cbs.model.*" xmlns:utils="flexed.utils.timeout.*">

             

            <mx:RemoteObject id="initInfoUCFlexRO" destination="initInfoUCFlexRO">
                <mx:method name="getInitInfo" result="handleGetInitInfoResult(event)" fault="handleGetInitInfoFault(event)" />
            </mx:RemoteObject>
            <mx:RemoteObject id="mainMenuUCFlexRO" destination="mainMenuUCFlexRO">
                <mx:method name="getXMLDocument" result="handlegetXMLDocumentResult(event)" fault="handlegetXMLDocumentFault(event)"/>
            </mx:RemoteObject>
            <mx:RemoteObject id="branchDetailsUCFlexRO" destination="branchDetailsUCFlexRO">
                <mx:method name="read" result="handleReadResult(event)" fault="handleReadFault(event)"/>
                <mx:method name="stnIP" result="handleStnIPResult(event)" fault="handleStnIPFault"/>
            </mx:RemoteObject>

             

            <mx:Script>
                <![CDATA[
                    import mx.controls.RadioButton;
                    import mx.events.CloseEvent;
                    import flexed.utils.timeout.*;
                    import mx.core.EdgeMetrics;
                    import mx.core.Container;
                    import com.citizen.cbs.vo.ApplicationInitInfo;
                    import com.citizen.cbs.CitizenApplication;
                    import mx.rpc.events.FaultEvent;
                    import mx.rpc.events.ResultEvent;
                    import mx.modules.IModuleInfo;
                    import mx.modules.ModuleManager;
                    import mx.events.ModuleEvent;
                    import mx.controls.Alert;
                    import mx.managers.CursorManager;
                    import mx.events.DynamicEvent;
                   
                    private var info:IModuleInfo = null;
                   
                    [Bindable]
                    private var XMLDocument:XML;
                    [Bindable]
                    private var branchCode:int;
                   
                    //passed to the component as value of onTimeOut attribute
                        private function onTimeOutHandler(e:Event=null):void
                        {
                            Alert.show("The Client has been timed out due to inactivity","Timeout Message by Method call",(Alert.OK),this,autoLogout);
                        }
                       
                        private function autoLogout(event:CloseEvent):void{
                            if(event.detail==Alert.OK){
                               
                            }
                            var str:String="/citizenProject/LogoutServlet";
                            //var jscommand:String = "window.open('"+str+"','win','toolbar=no,scrollbars=yes,resizable=1');";
                            var url:URLRequest = new URLRequest(str);
                            navigateToURL(url, "_self");
                        }
                       
                       
                        //Fired when the appTimedOut event occurs in the component
                        private function appTimedOutHandler(devent:DynamicEvent):void{
                            var expiryTime:String = devent.expiryTime.toString();
                            //Alert.show("The Client has been timed out at "+expiryTime,"Timeout Message by Event trigger");
                        }
                       
                       
                           
                    private function init():void
                    {
                        branchDetailsUCFlexRO.read();
                        branchDetailsUCFlexRO.stnIP();
                    }
                   
                    public function unloadModule():void {
                        var ref:URLRequest=new URLRequest("javascript:location.reload(true)");
                        navigateToURL(ref,"_self"); 
                        treeBox.percentWidth = 25;
                        treeBox.enabled = true;
                        treeBox.visible = true;
                        formLoader.unloadModule();
                       
                    }
                    private function handleGetInitInfoResult(event:ResultEvent):void {
               
                        CitizenApplication.initInfo = ApplicationInitInfo(event.result);
                        var user:String = CitizenApplication.initInfo.registeredUser.uamCode;
                        mainMenuUCFlexRO.getXMLDocument(branchCode, user);
                    }
                   
                    private function handleGetInitInfoFault(event:FaultEvent):void {
                        Alert.show("Error in Getting Init Info : " + event.fault.faultString);
                    }
                   
                    private function handleStnIPResult(event:ResultEvent):void
                    {
                        lblStn.text=String(event.result);
                    }
                   
                    private function handleStnIPFault(event:FaultEvent):void
                    {
                        Alert.show("Error in Getting Station IP : " + event.fault.faultString);
                    }
                   
                    private function handlegetXMLDocumentResult(event:ResultEvent):void
                    {
                        XMLDocument = event.result as XML;
                    }
                   
                    private function handlegetXMLDocumentFault(event:FaultEvent):void
                    {
                        Alert.show("Error In Getting XML Document: "+event.fault.faultString,"ERROR!!!!");
                    }
                   
                    private function handleReadResult(event:ResultEvent):void
                    {
                        branchDetailsVO = BranchDetails(event.result);
                        branchCode = branchDetailsVO.bdBranchNo;
                        initInfoUCFlexRO.getInitInfo();
                   
                    }
                    private function handleReadFault(event:FaultEvent):void{
                        Alert.show(event.fault.faultString);
                    }
                   
                   
                   
                   private function loadModule(selectedItem:Object):void                               //Loading Module
                    {
                        var moduleToOpen:String = selectedItem.@data;            /* ******* */
                        if (moduleToOpen.length == 0) {
                            return;
                        }
                       
                        var parameters:String = selectedItem.@parameters;
                        var allParameters:Array = parameters.split(",");
                        CitizenApplication.menuParameters  = new Object();
                        for (var i:int = 0; i < allParameters.length; i++) {
                            var parameter:String = allParameters[i];
                            CitizenApplication.menuParameters[parameter.split("=")[0]] = parameter.split("=")[1];
                        }
                        var moduleurl:String = moduleToOpen+'?'+Math.random();
                        formLoader.url = moduleurl;
                        //Alert.show("URL: "+moduleurl,"Message!!!!");
                        formLoader.loadModule();
                        treeBox.enabled = false;
                        treeBox.visible = false;
                        treeBox.percentWidth = 0;
                    }

                   
                    private function moduleEventHandler(event:ModuleEvent):void {
                        moduleCanvas.addChild(info.factory.create() as DisplayObject);
                    }
                   
                    private function handleModuleLoaderError(event:ModuleEvent):void {
                        trace(event.errorText  + " - " + event.bytesLoaded + " -- " + event.bytesTotal + " -- " + event.module);
                       
                    }
                   private function reloadpage(event:ModuleEvent):void                                                                     //This Function is required so that the modules work
                    {
                        var ref:URLRequest=new URLRequest("javascript:location.reload(true)");
                        navigateToURL(ref,"_self");
                    }

                       
                ]]>
            </mx:Script>
            <utils:ClientIdleTimeOut id="myTimeOut" onTimeOut="onTimeOutHandler" listenKeyStroke="true" listenMouseMove="true"
                timeOutInterval="5" confirmInterval="5"/>
            <model:BranchDetails id="branchDetailsVO"/>
            <mx:XML id="mainMenu" source="/assets/xml/mainmenu.xml" format="xml"/>
                <mx:DateFormatter id="df" formatString="DD-MM-YYYY" />
                <mx:ApplicationControlBar horizontalAlign="center" width="90%" x="60" y="0">
                    <!--<mx:MenuBar   dataProvider="{mainMenu}" labelField="@label" showRoot="false"  itemClick="loadModule(event.item)" />-->
                    <mx:Label text="Ver.No.: R1872" fontWeight="bold" fontSize="12" color="#000000"/>
                   
                    <mx:Label text="Station No.:" color="#000000" fontFamily="san" fontWeight="bold"/>
                    <mx:Label text="--" color="#000000" id="lblStn" fontFamily="san" fontWeight="bold"/>
                   
                    <!--<mx:MenuBar     dataProvider="{mainMenu}" labelField="@label" showRoot="false"  itemClick="loadModule(event.item)" />-->
                    <mx:Spacer width="100%" />
                    <mx:Text fontWeight="bold" text="{CitizenApplication.initInfo.registeredUser.branchDetails.bdBankName}"  styleName="appctrl"/>
                    <mx:Text fontWeight="bold" text="-"  styleName="appctrl"/>
                    <mx:Text fontWeight="bold" text="{CitizenApplication.initInfo.registeredUser.branchDetails.bdBranchName.toUpperCase( )}"  styleName="appctrl"/>
                    <mx:Text fontWeight="bold" text="BRANCH"  styleName="appctrl"/>
                    <mx:Spacer width="100%" />
                    <mx:Text fontWeight="bold" text="{CitizenApplication.initInfo.registeredUser.uamName}"  styleName="appctrl"/>
                    <mx:Text fontWeight="bold" text="|"  styleName="appctrl"/>
                    <mx:Text fontWeight="bold" text="{df.format(CitizenApplication.initInfo.registeredUser.branchDetails.bdCurrentWorkin gDt)}"  styleName="appctrl"/>
                </mx:ApplicationControlBar>
                <mx:HDividedBox id="divBox" width="100%" height="100%" shadowDirection="center" resizeToContent="true" liveDragging="true" horizontalGap="10" x="0" y="34">
                    <mx:VBox width="274" id="treeBox" borderStyle="solid" borderColor="#6699CC"><mx:Tree backgroundColor="#000000" color="#FFFFFF" width="100%" height="100%" id="treeMenu" dataProvider="{XMLDocument}" labelField="@label" showRoot="false"
                            itemClick="loadModule(treeMenu.selectedItem)"/>
                        <!--<mx:Tree backgroundColor="#000000" color="#FFFFFF" width="100%" height="100%" id="treeMenu" dataProvider="{XMLDocument}" labelField="@label" showRoot="false"
                            itemClick="loadModule(treeMenu.selectedItem)"/>-->
                    </mx:VBox>
                      <mx:Canvas id="moduleCanvas" width="100%" height="100%" styleName="mmc">
                     <mx:ModuleLoader backgroundColor="#000000" color="#FFFFFF" error="handleModuleLoaderError(event)"
                         updateComplete="treeMenu.height = moduleCanvas.height-2" loading="CursorManager.setBusyCursor()" 
                         useHandCursor="true"   ready="CursorManager.removeBusyCursor()" autoLayout="true"  
                         verticalAlign="middle" horizontalAlign="center" id="formLoader" width="100%" height="100%" />
                      </mx:Canvas>
                </mx:HDividedBox>
                <mx:Style source="CbsDesignFinal.css"/>
            </mx:Application>

            • 3. Re: Module Loader Problems In Flex....
              Gaurav J Adobe Employee

              Do you see the update dmoduleurl when you click on a new item in the tree?

               

              Module url change also triggers a module load, so no need to do formLoader.loadModule(); after formLoader.url = moduleurl;

               

              -Gaurav

              http://www.gauravj.com/blog



                         

              • 4. Re: Module Loader Problems In Flex....
                Flex_Crazy Level 1

                  private function loadModule(selectedItem:Object):void                               //Loading Module
                        {
                            var moduleToOpen:String = selectedItem.@data;            /* ******* */
                            if (moduleToOpen.length == 0) {
                                return;
                            }
                           
                            var parameters:String = selectedItem.@parameters;
                            var allParameters:Array = parameters.split(",");
                            CitizenApplication.menuParameters  = new Object();
                            for (var i:int = 0; i < allParameters.length; i++) {
                                var parameter:String = allParameters[i];
                                CitizenApplication.menuParameters[parameter.split("=")[0]] = parameter.split("=")[1];
                            }
                            var moduleurl:String = moduleToOpen+'?'+Math.random();
                            formLoader.url = moduleurl;
                            //Alert.show("URL: "+moduleurl,"Message!!!!");
                            formLoader.loadModule();
                            treeBox.enabled = false;
                            treeBox.visible = false;
                            treeBox.percentWidth = 0;
                        }

                 

                 

                @Gaurav I think thats wat i have done already.....any other solution....