Reputation: 131
I am working on a project where I need to continuously create and update an XML file. The only feasible way to do this is with PHP; I can't use FileReference in flash because it is Save As; I cannot use FileStream because I'm using Flash Player, not AIR; I don't want to use SharedObject because I need a user to be able to access the data in the XML from multiple computers.
Basically, whenever a user clicks on something, Flash grabs the color of that object. I need to put this color, each time it is clicked, into an XML file (there is only one file; it stores all of the colors, and is continuously updated). The reason it needs to be continuously updated is because there is no save button; once the user exits the page, they're done. I need their progress saved.
Is there a way to generate this XML using PHP/Flash? I understand how to generate an XML file in PHP, but I'm unsure on how to update it using Flash (which uses PHP).
The main idea I have right now is to use a loader in AS3 for the PHP file, which would grab the PHP file's data, which is the XML file. Once I load the PHP file in flash, can I modify this XML file using Flash? If not, how would I modify it using Flash to PHP?
Sorry if this is confusing; I spent hours creating a couple different ways using FileReference/FileStream, only to find out that it is not what I'm looking for.
Upvotes: 0
Views: 58
Reputation: 4649
I don't think you want to load the XML file into Flash and modify it there. If you do that then you'll only be modifying the data locally. Since you say there is no save button, the data will be lost when the user closes the page, unless you are continuously sending the XML file back to the server. That's a lot of unnecessary traffic.
A better solution might be to post a the color value to a PHP script each time the user clicks an object. The PHP could then add it to a database or XML file.
You'd send the values via a URLRequest.
Something like this:
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("myScriptURL.php");
request.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.userID = "Doug";
variables.colorValue = "blue";
request.data = variables;
// add handlers for completion, errors, etc (see the docs)
loader.load(request);
Upvotes: 1