4 Replies Latest reply on Feb 25, 2010 8:26 AM by Matt Le Fevre

    refresh screen and pass a parameter to the new screen on button click

    pratsing Level 1

      Hi all,

       

      I have a kind of strange problem although i have done it many times in .NET but being a flex newbie not able to do it in flex...

       

      I have a screen on which there is a text box and a submit button. Now on submit , i want screen to get refreshed and in new screen , i want the textbox to get filled with the value it contains in previous screen.

       

      I am able to refresh the screen on button click but not able to pass text box value to the new screen.

       

      Any help will be very grateful.....

       

      Thanks..

        • 1. Re: refresh screen and pass a parameter to the new screen on button click
          Matt Le Fevre Level 4

          possible to post some example code of what you're doing?

           

          not sure i understand..

          • 2. Re: refresh screen and pass a parameter to the new screen on button click
            pratsing Level 1

            // called after creation complete

            private function init()

            {

            textbox.text = // Query String that can be pass when screen is refreshed

            }

             

             

             

            // called on button click

            private function btnSubmit(event:Event):void

            {

                 // to refresh screen   

            flash.external.ExternalInterface.call("window.location.reload");

             

            }

            • 3. Re: refresh screen and pass a parameter to the new screen on button click
              paromitadey Level 1

              Hi,

               

              Not sure if I understood your problem correctly but this is what i could figure out.

              You have 2 Views (screens)

              View 1 - There is a TextBox (txtBox1) and a Button

              View 2 - There is a TextBox (txtBox2).

               

              You enter some value into the TextBox in View 1 and click on the button and navigate to View 2.

              You want the text (whatsoever) that was entered in View 1 to be displayed in the TextBox in View 2.

              If this is correct then you can use several ways to carry forward the text from one view to other namely -

               

              using Databinding

              <mx:TextInput id="txtBox2" text={txtBox1.text}/> or passing values through Events, variables etc.

               

              But if you want the second TextBox to be populated with some value in response to some sever call data (backend call), then it would be better if you could share some code snippet from your examples.

               

              Regards,

              Paromita

              • 4. Re: refresh screen and pass a parameter to the new screen on button click
                Matt Le Fevre Level 4

                hmm, not really sure what you're trying to accomplish with it!

                 

                but a simple way of passing data to the app would be using some kind of GET methodology, that is on the app load it searches the URL bar for info and then fills items with it. eg directing to a URL of:

                 

                 

                http://localhost/app.html#ExampleText

                 

                and using a function like

                 

                var stuff:String = ExternalInterface.call("window.location.href.toString");

                var nameParts:Array = stuff.split("#");

                var extensionless:String = nameParts[0]; 
                var extension:String = nameParts[1];    
                path = extension;

                 

                would then fill the variable 'path' with the string "ExampleText"

                 

                 

                which you could then feed into a textbox.

                 

                eg:

                 

                <?xml version="1.0" encoding="utf-8"?>
                <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="init()">
                <mx:Script>
                    <![CDATA[
                   
                        import flash.net.navigateToURL;

                 

                        [Bindable]
                        public var testStr:String = "";
                       
                        public function init():void
                        {
                            var stuff:String = ExternalInterface.call("window.location.href.toString");
                            var nameParts:Array = stuff.split("#");
                           
                              var extensionless:String = nameParts[0]; 
                              var extension:String = nameParts[1];    
                              testStr = extension;
                              
                           
                        }
                       
                       
                        public function refreshPage():void
                        {
                            var urlRequest:URLRequest = new URLRequest("http://localhost/test.html#" + txtBx1.text);
                           
                            navigateToURL(urlRequest, "_top");

                 

                        }
                       
                    ]]>
                </mx:Script>

                 

                    <mx:Button id="btn1" x="222" y="315" label="Button" click="refreshPage()"/>
                    <mx:TextInput id="txtBx1" x="176" y="285" text="{testStr}"/>
                   
                </mx:Application>