2 Replies Latest reply on Nov 17, 2006 2:17 AM by thespark

    as2 sendandload in as3

    thespark
      Okay this can't be that hard, but Ihave as2 script that loads xml, then i append few tags in it and send it to a php script.
      I use the following to send it myXML.sendAndLoad("processXML.php", receiverXML);
      in the processXML.php i have:
      <?php
      $file = fopen("guestbook.xml", "w+") or die("Can't open XML file");
      $xmlString = $HTTP_RAW_POST_DATA;
      if(!fwrite($file, $xmlString)){
      print "Error writing to XML-file";
      }
      print $xmlString."\n";
      fclose($file);
      ?>

      Now i just can't figure out how i do that in AS3.
      Can someone please help me with this?
        • 1. Re: as2 sendandload in as3
          Level 7
          Well, loading an xml document is fairly easy:

          import flash.net.*
          import flash.xml.XML
          import flash.event.*
          import flash.error.*


          var xml:XML = new XML("<doc></doc>")
          var url:String = "doc.xml";
          var request:URLRequest = new URLRequest(url);
          var loader:URLLoader = new URLLoader();
          loader.addEventListener(Event.COMPLETE, onComplete);
          loader.load(request);
          function onComplete(evt:Event){ trace(evt.target.data); }


          That said, if you change the URLRequest method to POST and attach some data,
          it should look like this. (Note: I don't have access to a web server at the
          moment, so this is not tested.)


          import flash.net.*
          import flash.xml.XML
          import flash.event.*
          import flash.error.*


          var xml:XML = new XML("<doc><node>Hello World</node></doc>")
          var url:String = "processXML.php";
          var request:URLRequest = new URLRequest(url);
          request.method=URLRequestMethod.POST;
          request.data = xml;

          var loader:URLLoader = new URLLoader();
          loader.addEventListener(Event.COMPLETE, onComplete);
          loader.load(request);

          function onComplete(evt:Event)
          {
          trace(evt.target.data);
          xml = new XML(evt.target.data)
          }


          • 2. Re: as2 sendandload in as3
            thespark Level 1
            Thanks! I will try that. This would be much easier with mysql or similar. Unfortuneatly I can't use that.