This Blog contains About Action script 3.0 Variables, Data types, Access specifies, Keywords, Operators, Conditional statements, Control statements, Arrays (Indexed, Associative, Multidimensional, Cloning), Functions, Symbols, Movie clips (Transformation point, Registration point, Loading images), Buttons, Events (Key board, Mouse, Timer, XML)Pre- defined function :- Random, Hit test object, Drag and drop, Sort, Loader, Tween,URL Loader, Video components, Audio Components, Sound Channel.
Friday, 8 March 2013
How to send data through xml in as3
Code :-
=====
var respTxt:TextField = new TextField();
var myTextFormat:TextFormat = new TextFormat();
myTextFormat.size = 14;
var xmlString:String = "<?xml version='1.0' encoding='ISO-8859-1'?><root><value>63</value></root>";
var book:XML = new XML(xmlString);
var xmlResponse:XML;
var xmlURLReq:URLRequest = new URLRequest("processPHP.php");
xmlURLReq.data = book;
xmlURLReq.contentType = "text/xml";
xmlURLReq.method = URLRequestMethod.POST;
var xmlSendLoad:URLLoader = new URLLoader();
//xmlSendLoad.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
//xmlSendLoad.addEventListener(IOErrorEvent.IO_ERROR, onIOError, false, 0, true);
xmlSendLoad.load(xmlURLReq);
function onComplete(evt:Event):void {
try {
xmlResponse = new XML(evt.target.data);
respTxt.text = xmlResponse;
removeEventListener(Event.COMPLETE, onComplete);
removeEventListener(IOErrorEvent.IO_ERROR, onIOError);
} catch (err:TypeError) {
respTxt.text = "An error occured when communicating with server:\n" + err.message;
}
placeText();
}
function onIOError(evt:IOErrorEvent):void {
respTxt.text = "An error occurred when attempting to load the XML.\n" + evt.text;
placeText();
}
function placeText():void {
respTxt.x = 15;
respTxt.y = 15;
respTxt.multiline = true;
respTxt.autoSize = TextFieldAutoSize.LEFT;
respTxt.setTextFormat(myTextFormat);
addChild(respTxt);
}
processPHP.php :-
=============
<?php
$file = fopen("docq.xml", "w+") or die("Can't open XML file");
$xmlString = $HTTP_RAW_POST_DATA;
if(!fwrite($file, $xmlString))
{
print "Error writing to XML-file";
}
print $xmlString."\n";
fclose($file);
?>
Out put XML :-
===========
<root>
<value>63</value>
</root>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment