4 Replies Latest reply on Jul 13, 2010 4:13 PM by Solydest

    textArea dataprovider ... please HELP!!!

    gth759k

      I need to load information from my server into a textArea ... is there anyway to have an httpService get data from the server in a php script and echo out the contents as a string and then place the response in the text area? I need help on this.

        • 1. Re: textArea dataprovider ... please HELP!!!
          rootsounds Level 4

          Set the String from the service result to either TextArea.text or TextArea.htmlText, depending upon what is appropriate.

          • 2. Re: textArea dataprovider ... please HELP!!!
            gth759k Level 1

            I still don't understand. Here's more information for what I need. I have an HTTPService

             

            <mx:HTTPService id="userRequest" url="http://localhost/myproj/connect.php" useProxy="false" resultFormat="text"/>

             

            At the very begining of the application I call creationComplete="userRequest.send();" in the application tag.

             

            My php script simply echos out text like this. <?php echo "Hello World"; ?>

             

            Then I have a textArea where I want my httpservice responce to go.

             

            <mx:TextArea id="mytext" width="100%" height="100%"></mx:TextArea>

             

            How do I get the "Hello World" text in the TextArea?

            • 3. Re: textArea dataprovider ... please HELP!!!
              rtalton Level 4

              Read the docs to understand how to handle your HTTPService results as there are different ways of doing it. Search for "Handling service results".

              • 4. Re: textArea dataprovider ... please HELP!!!
                Solydest

                As suggested, there are several possibilities so you should read the docs to better understand what those are, but to answer the question using your specific example: 

                 

                change your HTTPService tag to the following:

                 

                <mx:HTTPService id="userRequest" url="http://localhost/myproj/connect.php" 
                useProxy="false" resultFormat="text" result="mytext.text = event.result.toString()"/>
                

                 

                A more "proper" way would be to create a result handler function within a script block in your mxml file.  The function would take 1 parameter which would be of type ResultEvent and could look something like:

                 

                <fx:Script>
                     <![CDATA[
                          import mx.rpc.events.ResultEvent;
                               
                          private function userRequest_ResultHandler(resultFromServer:ResultEvent):void
                          {
                               mytext.text = resultFromServer.result.toString();
                          } 
                     ]]>
                </fx:Script>
                

                 

                you  can access the text sent back from your php in the ResultEvent object's "result" property.  It is of type Object and your text area's text property must be set to a String which is why we need the toString() part.

                 

                Next you would need to set the result property of of your HTTPService tag to call this function as such:

                 

                <mx:HTTPService id="userRequest" url="http://localhost/myproj/connect.php" 
                useProxy="false" resultFormat="text" result="userRequest_ResultHandler(event)"/>
                
                
                

                 

                Notice that you must include the (event) part because userRequest_ResultHandler expects one parameter which is the result of userRequest.send()

                 

                Cheers