5 Replies Latest reply on Jun 29, 2007 11:47 AM by ntsiii

    How do I send a message to my flex app

    CameronI
      I am really new to flex and I am trying to build a prototype. We need to have the browser post some data to the server and then have the server interpret that data. Once that is completed we need to have the server send a command back to the calling flex app to display a certain page within the flex app. Could some one point me in the right direction?

      I.e. we have 3 tabs in the flex app we need the client to send an xml string and then have the server send back a message telling the client to display tab 2.


      Thanks for your time.
        • 1. Re: How do I send a message to my flex app
          ntsiii Level 3
          You will want to use ExternalInterface. It is really quite easy to use. I don't have an example handy.

          Tracy
          • 2. Re: How do I send a message to my flex app
            NumberNineteen
            You can use "URLRequest" to call a server side script and then wait for a response using an event listener. Example:

            public function getURL():void {
            var variables:URLVariables = new URLVariables("i=myvar");
            var url:URLRequest = new URLRequest(' http://yourserver.com/script.php');
            url.method = URLRequestMethod.POST;
            url.data = variables;
            var loader:URLLoader = new URLLoader();
            loader.dataFormat = URLLoaderDataFormat.VARIABLES;
            loader.addEventListener(Event.COMPLETE, completeFunction);
            loader.load(url);
            }

            public function completeFunction(event:Event):void {
            mytabs.selectedIndex = event.target.data.response;
            }

            Your server side script should print something like "response=3" - for example, in PHP it would be:

            echo "response=" . tabIDtoReturn;

            • 3. Re: How do I send a message to my flex app
              ntsiii Level 3
              Ah, we have answered two different questions. if you need to have the browser (javascript) initiate a message to the Flex app, then ExternalInterface is the answer. If you want to send a data request to the server and get a response, then the data service call is the answer.

              I want to offer an alternative to NumberNinteen's URLLoader suggestion, and that is HTTPService. They are really the same underneath, but I find HTTPService a little simpler to use.

              Tracy
              • 4. Re: How do I send a message to my flex app
                CameronI Level 1
                Thanks for the suggestions! I have a client app(not the flex app) that receives information about the person on the phone passed from the server. I need to update the server and then have the flex app receive the response and do what ever it needs with it, most likely just display the appropriate page. I think I have found a way to fake it, in that I can have the browser do a post and then just reload the flex page. Then on the onload of the page look for a property in the response. I will definitely check out the HTTPService as I think that will help me quite a bit, since I am using SEAM on the backend.

                Thanks!!
                • 5. Re: How do I send a message to my flex app
                  ntsiii Level 3
                  Ah, no, then in your case you want to use ExternalInterface. This allows you to set up a callback function in Flex that gets called by the javascript.

                  So the non-flex calls the javascript function and that calls the Flex method.

                  Tracy