PDA

View Full Version : Saving Flash to XML File



tunnel
March 5th, 2004, 02:30 AM
I'm trying to save a variable from one flash file to server in form of a XML node, so that i can refer this xml file node in another flash file. can any one tell me how to save the XML file using flash

thanks for the help?

:sen:

λ
March 5th, 2004, 02:32 PM
do you have a server side language(eg PHP or ASP or ColdFusion)?

If you don't then it is impossible.

Flashmatazz
March 6th, 2004, 05:25 AM
I also want to do this, and I do have PHP.
I haven't been able to find useful information about how to write to an existing XML file though :(

Does anybody know how to do this?

λ
March 6th, 2004, 07:16 AM
Originally posted by Flashmatazz
I also want to do this, and I do have PHP.
I haven't been able to find useful information about how to write to an existing XML file though :(

Does anybody know how to do this?

The basic technique is to read the XML file into memory, and then process the string to become what you want the xml file to be.
Then you truncate the file to be empty, and write it with the string.

(with Flash, then Flash would send the PHP file the XML string, and then that would be written)

That's the basic method(sorry for the lack of code, I haven't got Apache/PHP installed on this box yet) :)

Flashmatazz
March 12th, 2004, 05:24 AM
Still haven't found how I should write the new contents to the XML file.

If anyone knows exactly how to do this.... please help

λ
March 12th, 2004, 11:45 AM
<?php
$file = fopen("yourfile.xml", "w+"); //the w+ mode truncates the file to 0 length for us :)
$xmlString = $_GLOBALS["HTTP_RAW_POST_DATA"]; //you need to use this with xml.send()
print "XML:".$xmlString."\n";
if(!fwrite($file, $xmlString)){
print "Error :(";
}
fclose($file);
?>

that ought to work with XMLObj.send()

not tested though, I'm under Linux atm.

Flashmatazz
March 13th, 2004, 10:56 AM
Sorry for being a pain in the b*tt but I'm still having problems here.

The thing is I want to create an XML guestbook, since I don't have an mysql database.

So I read in the contents of the xml-file into flash and I have a few fields that the user can fill out.
If the user clicks a submit button, would I need to send the entire xml object to php?

I tried this


// **** Load XML ****************************
my_XML = new XML();
my_XML.ignoreWhite = true;
my_XML.onLoad = function(success){
if (success){
myText = _root.container.myField;
myText.autosize = "center";
numItems = my_XML.firstChild.childNodes.length;
numFields = my_XML.firstChild.firstChild.childNodes.length;
for (i=0; i< numItems; i++){
for (j=0; j< numFields; j++){
myText.text += my_XML.firstChild.childNodes[ i].childNodes[j].firstChild.nodeValue + "\n";
}
myText.text += "\n";
}
}
else{
trace("Er is een fout opgetreden bij het laden van de XML file");
}
}
myIdentifier=Math.round(Math.random()*10000);
my_XML.load("test.xml?uniq="+myIdentifier);

myButton.onRelease = function(){
my_XML.send("processXML.php");
}

where processXML.php contains the code you posted above.

I tried to write it do a different xml-file than the file which is being read into flash, but I end up with this file being totally empty so it looks like something goes wrong with the sending of the xml-file.

Wouldn't it be possible to just send the text that the user inputs as 'normal' variables and make the php script so that it appends this as xml to the original file.

Sorry if I don't make any sense, but I'm quite new to serverside scripting.

Hope you can help

Flashmatazz
March 14th, 2004, 12:18 PM
Ok, after much fiddling around I finally got it to work :P

I made a small change in the php-code:


$file = fopen("gastenboek.xml", "w+");

added this in my AS:


my_XML.onLoad = function(success){
my_XML.contentType = "text/xml";

this way the xml-file was actually being written to.

I then made changes in th AS: instead of a xml.send() action I now use xml.sendAndLoad to get the xml-data back into flash to show the new contents of the guestbook directly.

You can see it working on the band site I created recently: www.tenx.nl

Thanks njs12345 for the help :thumb:

tunnel
March 15th, 2004, 01:17 AM
Thanks to all your effort...

biach
August 11th, 2004, 08:32 PM
can u also post the xml file? im also in the process of thinking for a solution and i cant seem to trace it without the xml file..thanks!!!

redanchor
August 14th, 2004, 09:27 PM
http://www.kirupa.com/web/xml_guestbook.htm

Ierend
July 29th, 2008, 07:18 AM
Hi there,

I happened here in this forum while searching for a way to solve my problem.

I've already read all senocular's tutorial about flash and XML and all the tutorial about how_to_create_an_xml_guestbook.
The application i'm trying to realize is a simple "news editor", and I've noticed that all the solutions for the guestbook can be applied as well to solve my problem.
In fact i've adapted the code for my application, and i've also created a php_xml_manipulation_file that looks just like the one in the tutorial, but I still can't get it working.

But there's more!
I've downloaded the source of the guestbook application, exported it in the correct way, and I've uploaded the whole folder in my website (just to check a "working application").
Wonders and magic: In my site, the guestbook application doesn't work!!!

The problem, in both cases, is that the new XML (sent from the swf with the sendAndLoad function) is not saved on the correct file (i mean: it is not saved at all). I tried to look at the php settings of my web space, but i couldn't find anything missing (although, i might have been looking in the wrong places).

So I ask you a little help.
I'm litterally going out mad since when i got stuck with this problem.
I'll attach a couple of codes:



l_xml=false;

var load_xml = new XML();
var receiver = new XML();
var serverside = "tramite2.php";
var xmlfile = "news.xml";

load_xml.ignoreWhite;
receiver.ignoreWhite;

load_xml.onLoad = function(success) {
this.contentType="text/xml";
if (success) l_xml = true;
}

receiver.onLoad = function() {
this.contentType="text/xml";
trace("ricevuto!");
trace(this);
}

myIdentifier=Math.round(Math.random()*10000);
load_xml.load("news.xml?uniq="+myIdentifier);

okbtn.onRelease = function() {
if(l_xml){
var tempdata = date.text; trace(tempdata); //these traces are to keep the track
var templuogo = luogo.text; trace(templuogo);
var temptitolo = titolo.text; trace(temptitolo);

nuovoelemento = load_xml.createElement("concerto");
trace(nuovoelemento);

load_xml.firstChild.appendChild(nuovoelemento);
load_xml.firstChild.lastChild.attributes.data = tempdata;
load_xml.firstChild.lastChild.attributes.luogo = templuogo;
load_xml.firstChild.lastChild.attributes.titolo = temptitolo;
load_xml.firstChild.lastChild.createTextNode(body. text);

trace(load_xml);
//HERE is a strange thing: the new element i've just appended is not shown calling the trace function... don't have a clue...
salva();
}
}

function salva(){
load_xml.sendAndLoad("tramite2.php", receiver);
}And then the PHP (this is the first version i tried, from senocular's tutorial):


<?php
$filename = "news.xml";
$raw_xml = file_get_contents("php://input");

print $raw_xml;

$fp = fopen($filename, "w");
fwrite($fp, $raw_xml);
fclose($fp);
?>
(and the second one:)


<?php
$xmlString = $HTTP_RAW_POST_DATA;
if (is_null($xmlString)) {

print "No data was sent";

}
else {

$file = fopen("news.xml", "w+") or die("Can't open XML file");
if(!fwrite($file, $xmlString)){

print "Error writing to XML-file";

}
print $xmlString."\n";
fclose($file);

}
?>
Please help me...

My english is not the best you can find, so if any of the explanations is not clear enough, just ask, and i'll try to explain myself better...

Thank you..

I