Views
Replies
Total Likes
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
importmx.controls.Alert;
importflash.events.*;
importflash.net.*;
importmx.collections.XMLListCollection;
importmx.rpc.http.*;
importmx.rpc.events.*;
importflash.net.FileReference;
importmx.core.Application;
//Objects
private var requestXML:XML= newXML();
private var loadRequest:HTTPService= newHTTPService();
private var sendRequest:HTTPService= newHTTPService();
private var variables:Object= newObject();
private var uploadRequest:URLRequest= newURLRequest();
private var uploadLoader:URLLoader= newURLLoader();
private var uploadVars:URLVariables= newURLVariables();
private var fileUpload:FileReference= newFileReference();
//Bindable
[
Bindable] public varimageString:String;
[
Bindable] public vartopString:String;
[
Bindable] public varbottomString:String;
[
Bindable] public varoutImage:String;;
[
Bindable] public varoutTop:String;
[
Bindable] public varoutBottom:String;
[
Bindable] public varglobal_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
asXML;
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);
?>
Views
Replies
Total Likes