4 Replies Latest reply on Dec 7, 2011 5:39 PM by t4sca

    Adobe AIR communicate with PHP

    Yue_Hong Level 1



      How can I have Adobe AIR program to communicate with PHP? For example, I need my app to get some value from PHP and display it. I have tried with "webservice" and using the example I found here: http://dimuthuc.blogspot.com/2008/01/php-webservice-consume-from-flex.html. But it doesn't work, and it shows "Error #1088: The markup in the document following the root element must be well-formed."


      How can I get it works? Is there any other good example? Thanks.

        • 1. Re: Adobe AIR communicate with PHP
          Claudiu Ursica Level 4

          This sounds like a server side error or null value to me. Debug it on php side....



          • 2. Re: Adobe AIR communicate with PHP
            Yue_Hong Level 1

            My php is exactly the same as from the example from http://dimuthuc.blogspot.com/2008/01/php-webservice-consume-from-flex.html.


            I am totally no idea how Flex work with PHP. Will Flex able to grape a value of the PHP which I simply do an echo on PHP side?



            Here is my flex AIR code:


            <?xml version="1.0" encoding="utf-8"?>

            <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"




                    <!-- Place non-visual elements (e.g., services, value objects) here -->

                    <s:WebService id="service" wsdl="http://localhost/online/test.php"

                                  useProxy="false" showBusyCursor="true" result="service_resultHandler(event)" fault="service_faultHandler(event)" />




                        import mx.controls.Alert;

                        import mx.rpc.events.FaultEvent;

                        import mx.rpc.events.ResultEvent;


                        private function callService():void






                        protected function service_resultHandler(event:ResultEvent):void


                            // TODO Auto-generated method stub

                            result.text = event.result.toString();



                        protected function service_faultHandler(event:FaultEvent):void


                            // TODO Auto-generated method stub

                            Alert.show(event.fault.faultString, event.fault.faultCode);





                <s:Panel id="pnlMain" x="10" y="10" width="450" height="250" title="My Greeting Client">

                    <s:TextArea x = "10" y="15" id="input" editable="true" width="400" height="50" />

                    <s:TextArea x = "10" y="100" id="result" editable="false" width="400" height="50" />

                    <s:Button x="10" y="170" label="Call WebService"

                               id="butJSDisplay" click="callService()"/>





            PHP file:




            /** greet function

              * @param string $name

              * (map to xs:string)

              * @return string $greetReturn

              * (map to xs:string)




            function greet($name)


               $result = array ('greetReturn' => "Greetings, ".$name);


               return $result;



            $operations = array('greet' => 'greet');

            $parameters = array('greet' => 'MIXED');


            $service = new WSService(array


                           'operations' => $operations,

                           'opParams' => $parameters





            • 3. Re: Adobe AIR communicate with PHP
              Claudiu Ursica Level 4

              You need to debug the php side first see if the name gets from flex to php, and then if so move on towards building the response. I don't have php installed here so i cannot run it (; .


              • 4. Re: Adobe AIR communicate with PHP

                That blog post made my head hurt.




                * My ActionScript Call.




                private function getData(event:Event):void


                          busyIndicator.visible = true;



                          var _params:Object = new Object();

                          _params.CustomerID = data.Customer.ID;


                          var _getData= new HTTPService();

                          _getData.url = "http://" + FlexGlobals.topLevelApplication.SERVER + "/GetData.php";


                          _getData.addEventListener(FaultEvent.FAULT, fhHttpService);

                          _getData.addEventListener(ResultEvent.RESULT, rhGetData);






                * PHP : If it's simple data I usually just echo as is, if it's somewhat complex data, I get PHP to create xml, and echo the xml.





                echo ($Data);