hi I usually load the XML and manipulate it with Actionscript. When I am done, I POST the updated XML to a PHP file which opens the file to be saved to and overwrite the contents.
<mx:Script>
<![CDATA[
//Import
import mx.controls.Alert;
import flash.events.*;
import flash.net.*;
import mx.collections.XMLListCollection;
import mx.rpc.http.*;
import mx.rpc.events.*;
import flash.net.FileReference;
import mx.core.Application;
//Objects
private var requestXML:XML= new XML();
private var loadRequest:HTTPService= new HTTPService();
private var sendRequest:HTTPService= new HTTPService();
private var variables:Object= new Object();
private var uploadRequest:URLRequest= new URLRequest();
private var uploadLoader:URLLoader= new URLLoader();
private var uploadVars:URLVariables= new URLVariables();
private var fileUpload:FileReference= new FileReference();
//Bindable
[
Bindable] public var imageString:String;
[
Bindable] public var topString:String;
[
Bindable] public var bottomString:String;
[
Bindable] public var outImage:String;;
[
Bindable] public var outTop:String;
[
Bindable] public var outBottom:String;
[
Bindable] public var global_Directory:String= Application.application.global_Directory;
//Methods
private function sendXML():void {
loadRequest.url= global_Directory+
"XML/about.xml";
loadRequest.method=
"POST";
loadRequest.resultFormat=
'e4x';
loadRequest.send(variables);
loadRequest.addEventListener(ResultEvent.RESULT, loadXML);
}
private function loadXML(event:ResultEvent):void {
requestXML= event.result
as XML;
display();
}
private function display():void {
image_about.source= requestXML.image;
input_image.text= requestXML.image;
input_top.htmlText= requestXML.top;
input_bottom.htmlText= requestXML.bottom;
}
private function upload():void {
uploadRequest.url=
"PHP/Actions.php";
uploadRequest.method=
"POST";
uploadRequest.data= uploadVars;
uploadVars.action=
"image_upload";
uploadVars.directory= global_Directory+
"/Images/About/";
fileUpload.upload(uploadRequest,
"image");
uploadLoader.load(uploadRequest);
fileUpload.addEventListener(Event.COMPLETE, uploadCompleted);
}
private function uploadCompleted(event:Event):void {
var image_url:String= global_Directory+"Images/About/"+event.target.name;
input_image.text= image_url;
image_about.source= image_url;
}
private function edit():void {
requestXML= <about><image /><top /><bottom /></about>;
requestXML.image= input_image.text;
requestXML.top= input_top.htmlText;
requestXML.bottom= input_bottom.htmlText;
update();
}
private function update():void {
sendRequest.url=
"PHP/Actions.php";
sendRequest.method=
"POST";
variables.action=
"edit_about";
variables.xmlString= requestXML;
variables.directory= global_Directory;
sendRequest.send(variables);
sendRequest.addEventListener(ResultEvent.RESULT, updateComplete);
sendRequest.addEventListener(FaultEvent.FAULT, updateFailed);
}
private function updateComplete(event:ResultEvent):void{
Alert.show(
"Update Complete");
}
private function updateFailed(event:FaultEvent):void {
Alert.show(
"Update failed.");
}
]]>
</mx:Script>
<?php
$action= $_POST['action'];
$xmlString= $_POST['xmlString'];
$directory= $_POST['directory'];
$path = "../".$directory."XML/users.xml";
$file = fopen($path, 'w');
fwrite($file, $xmlString);
fclose($file);
?>