Copy link to clipboard
Copied
Hello, I need to build a simple database (3 elements total) using XML and make the swf interact with it.
What I need is an interface that pops out if you've done a better score (better than the 3 saved in the XML).

Then you insert your name, send it with the proper button (or clear the field with the reset one) and then get a new classification in the txt field below dividing the players with their score.
To do this, since I wasn't able to do it on my own, I've found a ready-script and this is it:
var input_xml = new XML();
input_xml.ignoreWhite = true;
input_xml.contentType = "text/xml";
input_xml.onLoad = function(success){
if (success) input_txt.text = this.firstChild.firstChild.nodeValue;
else input_txt.text = "Error loading input XML";
}
var output_xml = new XML();
output_xml.ignoreWhite = true;
output_xml.onLoad = function(success){
if (success) output_txt.text = this.firstChild.firstChild.nodeValue;
else output_txt.text = "Error loading output XML";
}
var xml_file = "readwrite/simple_edit.xml";
var server_file = "simple_save.php";
load_btn.onRelease = function(){
input_txt.text = "Loading...";
input_xml.load(xml_file + "?uniq=" + new Date().getTime());
}
send_btn.onRelease = function(){
input_xml.parseXML("<edit> new text </edit>");
input_xml.firstChild.firstChild.nodeValue = input_txt.text;
input_xml.xmlDecl = ""; // declaration duplication bug
input_xml.sendAndLoad(server_file, output_xml);
output_txt.text = "Loading...";
}
clearin_btn.onRelease = function(){
input_txt.text = "";
}
this must be integrated with the following PHP code:
<?php
$filename = "readwrite/simple_edit.xml";
$raw_xml = file_get_contents("php://input");
print $raw_xml;
$fp = fopen($filename, "w");
fwrite($fp, $raw_xml);
fclose($fp);
?>
as you can see the script is in AS2 and that's why it isn't working.
Could you help me "translating" it in AS3? Or even show me an AS3 working example?
Copy link to clipboard
Copied
Below is a clean tutorial on xml AS3:
http://www.republicofcode.com/tutorials/flash/as3xml/
Copy link to clipboard
Copied
Thank you for answering relaxatraja but this tutorial just read the XML (as its title'Loading XML data').
I also need to write my XML to insert into the new score and then read it again.
Shortly:
1) Read the XML to find the 3 best scores;
2) Compare the 3 scores with the actual score;
3) If the actual score is better than one of them the interface pop;
4) The user insert his name;
5) Name and score are written on the XML
5) Read again the XML.
Copy link to clipboard
Copied
You'r not able to write data into xml directly from flash. you should use some server side scripting like php or asp to achieve.
Copy link to clipboard
Copied
Yes, I know that.
In the script I've found in fact there is this PHP page:
<?php
$filename = "readwrite/simple_edit.xml";
$raw_xml = file_get_contents("php://input");
print $raw_xml;
$fp = fopen($filename, "w");
fwrite($fp, $raw_xml);
fclose($fp);
?>
The code I've added in the first post works properly and I would use that if it weren't in AS2.
Copy link to clipboard
Copied
http://blog.turtlebite.com/send-and-load-variables-with-as3-and-php/
Copy link to clipboard
Copied
This seems interesting but would you like to explain me some things?
First of all what's the difference between GET and POST?
And after that, how can I customize that example to make it work updating my XML instead of returning a simple txt message?
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more