5 Replies Latest reply on Jul 13, 2010 10:01 AM by Flex harUI

    How to refresh data in a module?

    barnetj1

      Hi all,

      I currently have a flex app. This app has a container and the container switches between modules by switching between container states.. The problem is when a user comes in and, for example, wants to create a plan. He/She gives the plan a name, then hits submit.. This then changes the container state which displays a different module, which just shows the name of the plan the user has inputted in the previous state/module..

       

      Now the user hits create plan again, but this time when the user enters a different name and hits submit, the name of the plan on the review state, is the same as when he/she named a plan the 1st time around..

       

      Is there any type of state.refresh(), or module.reload() method?

       

      Thanks All

        • 1. Re: How to refresh data in a module?
          Flex harUI Adobe Employee

          If the module controls are bound to a data model you shouldn't be having a

          problem.

          • 2. Re: How to refresh data in a module?
            barnetj1 Level 1

            Thats the thing.. I am using a data model, that gets instantiate in the main.mxml file, this data model gets passed to the 1st module, where all properties of the model are set.. Then the model gets passed to the second module where all properties of the model are displayed for review purposed.. On the second loop through, the new values are set in model, just not being displayed.. the 2nd module just displays the old values..


            CODE:

            model.as

             

            package components.models
            {
                public class model
                {
                    // ------- Properties -------
                    [Bindable]
                    public var name:String;

             

                    public function set name(item:String):void
                    {
                        name = item;
                    }
                   
                    public function get name():String
                    {
                        return name;
                    }

            }

             

            ////////////////

            main.mxml

             

            import components.models.model;
                    import mx.controls.Alert;
                    import flash.utils.flash_proxy;
                   
                    import flashx.textLayout.tlf_internal;
                   
                    import mx.core.mx_internal;
                    import mx.events.FlexEvent;
                   
                    import org.osmf.utils.URL;
                   
                    [Bindable]
                    public var myModel:model = new model();

             

            mxml code: instance of module 1 and 2...

             

            <mod:createName id="name" includeIn="name" x="310" y="199" model="{this.myModel}" >
            </modt:createName>

            <mod:reviewName id="review" model="{this.myModel}" includeIn="review" x="604" y="119" >
            </mod:reviewName>

             

            module 1 code(createName)

             

            <?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" width="580" height="320" >

             

                <fx:Script>
                    <![CDATA[
                        import components.models.model;
                       
                        public var model:model;

             

                        public function name():void
                        {
                            model.name = name.text;
                           
                        }
             
                        protected function save_name():void
                        {
                            this.name();
                            parentApplication.setCurrentState("review",true);
                        }
                       
                   
                      
                    ]]>
                </fx:Script>
               
                <s:Group x="47" y="44" width="514" height="237">
                   
                    <s:TextInput x="266" y="71" width="209" id="name" height="20"/>
               
                    <s:Button click="save_name()" id="button7" label="Save" x="380" y="289" width="81"/>
               
              
                </s:Group>
            </mx:Module>

             

             


            Second module(review Name)...

             

            <?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"
                           width="588" height="324" xmlns:d="http://ns.adobe.com/fxg/2008/dt" >

             

               
                <fx:Script>
                    <![CDATA[
                        import components.models.model;
                       
                        [Bindable]
                        public var model:model;       


                        [Bindable]
                        private var test:String;

             

                    ]]>
                </fx:Script>
               
                <s:Group width="100%" height="100%">
              
                <s:Label x="286" y="117" width="209" height="12" id="revewName" text="{this.model.name}"/>  

             

                </s:Group>
            </mx:Module>

             

            not sure what the problem is.. but that you for the reply..

            • 3. Re: How to refresh data in a module?
              Flex harUI Adobe Employee

              Are you getting warnings in the console?  Maybe model.name is not

              .

               

              Note that you are not using modules correctly.  By using tags directly in

              the main app, you are linking the module class directly into the main app

              and not deferring loading.

              • 4. Re: How to refresh data in a module?
                barnetj1 Level 1

                Thank you very much.. I appreciate all your help.. I figured out the problem.. Question can you give me a example of how I should be loading modules?

                Thanks

                • 5. Re: How to refresh data in a module?
                  Flex harUI Adobe Employee

                  The only declarative way is to use mx:ModuleLoader.  You should have a

                  shared interface that the module implements and your app expects to use.