View Full Version : save variable in xml

11-08-2006, 02:38 PM

I'm looking for some help on how to save a variable in a XML file.

Let say I load the following xml in my flash...

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



'Var1' & 'Var2' defines some variables in the flash, carrying the same name. These variables are changed at some point, and needs to be saved back into the same xml. Let's say I've changed them to '11111' and '11112'...

Now, I haven't got a clue how to save them, since I'm not that familar with either asp or php. Can anyone help me with this small task?

11-08-2006, 04:07 PM
It will require the use of a server side script, PHP or ASP.

Many more on google.

11-08-2006, 04:18 PM
yeah, thanks...

I know that it requires a server-side script. That's kinda why I posted in this topic.... ;)

I'm not looking to read up on all kinds of scripting, using god knows how many hours to do something - I guess- pretty simple...

Just wondering if some could actually provide me with a little bit of actionscript help and a php/asp script that writes to the xml.

11-08-2006, 04:38 PM
The basics

$filename = "guestbook.xml";
$raw_xml = file_get_contents("php://input");

print $raw_xml;

$fp = fopen($filename, "w");
fwrite($fp, $raw_xml);

11-09-2006, 02:14 PM

but I'm still a bit shaky on the actionscript part.

Let's say I've loaded my xml like this...

XMLfile = "data.xml";
objXML = new XML();
objXML.ignoreWhite = true;
objXML.onLoad = loadXML;
function loadXML(success) {
if (success) {
trace("loaded XML");
userData01 = objXML.firstChild.childNodes[0].firstChild;
userData02 = objXML.firstChild.childNodes[1].firstChild;
} else {
trace("failed to load XML");

Now, the "userData" variables have been set to '00000' and '00001' as the xml says.
Now I do something in the flash so the variables change to '11112' and '22223'

Now I have to save this back into the xml. And this is where I get lost. I know I have to post to the php script.... But I have no idea how. A little help?

11-09-2006, 04:26 PM
You could just use LoadVars() to send the data to the php file, no need for the XML object.

11-09-2006, 09:45 PM
I'm not sure we're on the same page...

Think of the data from the xml as... say a Highscore.

Let's pretend this is for a game. I load the data from the xml, which is a previous recorded score. I play again, and the score is changed. This will need to be saved back to the xml again, and by that I mean overwrite the previous score - in the same node.

Now, there is a need for the xml object... right?

Thanks for helping out btw :)

11-10-2006, 12:13 AM
the XMLobject doesnt have a save method, unless I missed something. I'll admit, I dont work much with XML. To save the data in the XML file, you wont be able to avoid using PHP.

11-10-2006, 12:23 AM
oh, I'm not trying to avoid the php. I know there isn't a direct save method. I do intend to use the php, but my problem isn't so much the php, but how to communicate with the script you provided.

I guess I should be more specific. Not quite sure how tho, so I'll try to explain step by step what I do, and where exactly I need help...

From the top...
I load the xml as posted. Define some variables from the nodes. Then as I walk throu my flash application and complete some steps, these variables are changed. Now I need them to be sent back to the XML - and overwrite the previous data. I know how to load and get the variables, change them... but how do I write to the php?

Based on my posts, could you give me an example on how the actionscript should interact with the php?

11-10-2006, 01:19 AM
I just found this, maybe it will be useful