4 Replies Latest reply on Aug 8, 2006 6:02 PM by cubum

    Get value XML return from PHP

    cubum
      PHP file:
      $Return .="<news><other><pagecount>$MaxPage</pagecount></other></news>";

      private function initApp():void {
      newsRequest.send();
      var xmlData:XML = new XML(newsRequest.lastResult.news.other);
      var PageCount:String = xmlData.pagecount.toString();
      }
      <mx:HTTPService id="newsRequest" url=" http://localhost/flex/news.php" useProxy="false" method="POST">

      But PageCount empty
        • 1. Re: Get value XML return from PHP
          peterent Level 2
          All data services in Flex are asynchronous. So you cannot make the call (send) and expect to look at the result immediately, not matter how fast everything is.

          You have 2 choices: either use a result event handler on the HTTPService or use data binding on the result.
          • 2. Re: Get value XML return from PHP
            cubum Level 1
            Sorry for my English!
            I using <mx:Text> binding data is ok, but i want assign value to variable String is PageCount. because i want add to combox value from 1 to PageCount for paging:
            for (i=1; i<=int(PageCount); i++) {
            numPageCount.push({label:i, idx:i});
            }
            <mx:ComboBox id="listPage" width="59" dataProvider="{numPageCount}" change="goPage();" labelField="label"/>
            Do you help me a example using String PageCount.. Thanks for your help!
            • 3. Re: Get value XML return from PHP
              peterent Level 2
              Set up your HTTPService like this:
              <mx:HTTPService id="newsRequest" url=" http://localhost/flex/news.php" useProxy="false" method="POST"
              result="handleResult(event)" resultFormat="e4x">

              When newsRequest.send() is executed, the handleResult function will be called when the result is sent back from the server. The resultFormat="e4x" makes sure that e4x XML parsing is used.

              Now, in a Script block add the following:

              [Bindable] private var PageCount:Number;
              [Bindable] private var numPageCount:ArrayCollection = new ArrayCollection();

              private function handleResult( result:ResultEvent ) : void
              {
              PageCount = Number(result.lastResult.pagecount);
              for(var i:Number=0; i < PageCount; i++) { numPageCount.addItem( {label:i, idx:i} ); }
              }

              Then you can use these values in data binding:

              <mx:Text text="{String(PageCount)}" />
              <mx:ComboBox dataProvider="{numPageCount}" ... />

              Because you want to have the ComboBox display a list you should use ArrayCollection instead of Array.
              • 4. Re: Get value XML return from PHP
                cubum Level 1
                ok, it has run. Thanks