0 Replies Latest reply on Mar 16, 2011 9:38 PM by The Aryeh

    Posting an Appended XML Object to Server using AS3 with PHP in Flex 4

    The Aryeh

      Hey Everyone,

       

      I've scoured the internet looking for help with this problem, and I'm assuming the issue is fairly obvious.  I'm guessing there is just something I'm not aware of going on here and my low-level knowledge can't pick it up.  What I'm trying to do is append an XML file on my hosting account with some XML data generated in my AIR app (I'm using Flash Builder 4 Burrito).  I'm using a small PHP script to tell it to do so, and its one that works in an AS3 flash animation/website/whatever (so I know it works to some extent).  Every time I try the code in my AIR app, however, it wipes my XML file clean and doesn't append anything.  I get a positive return on event complete though.  Heres my code:

       

       

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

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

         xmlns:s="library://ns.adobe.com/flex/spark"

         xmlns:mx="library://ns.adobe.com/flex/mx"

         creationComplete="appInit()">

       

       

      <fx:Script>

      <![CDATA[

      [Bindable]

      private var myXML:XML = new XML();

       

      private function appInit():void{

      goBtn.addEventListener(MouseEvent.MOUSE_UP, makeGroupbtn_clickHandler);

       

      }

      private function makeGroupbtn_clickHandler(event:MouseEvent):void{

      var newName:String="Pew";

      var newFull:String="Pew";

      var newItem:XML=XML("<tier><innertier>"+newName+"</innertier><innertiertwo>"+newFull+"</inner tiertwo><tier>");

      myXML.appendChild(newItem);

      myXML.toXMLString();

      var request:URLRequest=new URLRequest("http://www.mydomain.com/messages.php");

      request.data=myXML;

      request.contentType="text/xml";

      request.method=URLRequestMethod.POST;

      var loader:URLLoader = new URLLoader();

      loader.load(request);

      loader.addEventListener(Event.COMPLETE, check);

      HTTPStatusEvent.HTTP_RESPONSE_STATUS;

      }

      private function check(event:Event):void{

      trace("yes");

      }

      ]]>

      </fx:Script>

       

      <fx:Declarations>

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

      </fx:Declarations>

      <s:Button id="goBtn" x="285" y="317" label="Button"/>

      </s:WindowedApplication>

       

       

      Heres my PHP:

       

       

      <?php

      if (isset($GLOBALS["HTTP_RAW_POST_DATA"])){

          $xml = $GLOBALS["HTTP_RAW_POST_DATA"];

          $file = fopen("myxml.xml","wb");

          fwrite($file, $xml);

          fclose($file);

      }

      ?>

       

       

      Like I said, it works flawlessly on a website I have it running on.  As far as I can tell it has something to do with the AIR environment and its aversion to file loading.  I'm guessing that I just need to specify something else in order to get things working.  Thanks for your help guys.
      The Aryeh