loading external xml file


from 'learning actionscript 3' book i'm trying out reading/writing xml file.

 

actionscript:

var txtfld:textfield = new textfield();

txtfld.width = 500;

txtfld.height = 350;

txtfld.multiline = txtfld.wordwrap = true;

addchild(txtfld);

var str:string = "<?xml version='1.0' encoding='utf-8'?>";

str += "<value>sent actionscript</value>";

var xmltosend:xml = new xml(str);

var req:urlrequest = new urlrequest("save_xml.php");

req.data = xmltosend;

req.contenttype = "text/xml";

req.method = urlrequestmethod.post;

var urlloader:urlloader = new urlloader();

urlloader.addeventlistener(ioerrorevent.io_error,

                                                               onioerror, false, 0, true);

urlloader.addeventlistener(event.complete,

                                                               oncomplete, false, 0, true);

urlloader.load(req);

function onioerror(evt:ioerrorevent):void {

          txtfld.text = "xml load error.\n" + evt.text;

}

function oncomplete(evt:event):void {

          try {

                    urlloader.removeeventlistener(ioerrorevent.io_error, onioerror);

                    urlloader.removeeventlistener(event.complete, oncomplete);

                    var loadedxml:xml = new xml(evt.target.data);

                    txtfld.text = loadedxml.stuff;

          } catch (err:error) {

                    txtfld.text = "xml parse error:\n" + err.message;

          }

}

 

php:

<?php

if (isset($globals["http_raw_post_data"])){

          $data = xmldoc($globals["http_raw_post_data"]);

 

          $file = fopen("data.txt","wb");

          fwrite($file, $data);

          fclose($file);

 

          if (!$file) {

                    echo("<stuff>server unable create file.</stuff>");

          } else {

                    echo("<stuff>file saved.</stuff>");

          }

}

?>

 

i'm using mamp test it, servers running , both flash file , php script file in htdocs location. i'm trying out http://localhost:8888/send_load_xml.swf , in same location save_xml.php , data.txt.

 

when run swf 'xml load error #2032'. i've checked name of php file , txt file , correct. why getting error?

your swf can't execute php file.

 

you should upload server has php installed , working , test there or, test own php installation , server setup outside of flash.



More discussions in ActionScript 3


adobe

Comments

Popular posts from this blog

How to set the order of FAQs instead of alphabetical

Thread: Get UK Keyboard working

how do I change the e-mail address for my merchant account