I am using Flash 8. this is the only thing you need if you need to follow this example
On the flash IDE – stage need to have a Button Component (button name – submit_button) and Dynamic text with (result_ta)
If you want to send xml data from flash to your dynamic page,
you know the syntax – send("url","POST/GET")
if you want to load an XML data from a url you still know the syntax load("URL");
well how about sending an XML data to a server page and receiving the same as XML. Yes you are right it is sendAndLoad("URL", receiving Object, "GET/POST");
All of the above you can find in flash HELP, but there is a tricky part which has been left out.
Let me place the Actionscript first and then the PHP serverside script and explain in detail.
ActionScript:
var submitListener:Object = new Object();
submitListener.click = function(evt:Object) {
var result_lv:LoadVars = new LoadVars();
result_lv.onLoad = function(success:Boolean) {
if (success) {
result_ta.text = result_lv.welcomeMessage;
} else {
result_ta.text = "Error connecting to server.";
}
};
var result_xml:XML = new XML();
result_xml.ignoreWhite = true;
result_xml.onLoad = function(s){
if(s){
result_ta.text = this.firstChild;
}else{
result_ta.text = "Error connecting to server.";
}
}
var send_lv:LoadVars = new LoadVars();
var xm:XML = new XML("<root><name>vinod</name></root>");
xm.ignoreWhite = true;
xm.contentType = "text/xml";
send_lv.xm = xm;
send_lv.sendAndLoad("http://vinodvv/test/sendandloadxml.php", result_lv, "GET");
send_lv.sendAndLoad("http://vinodvv/test/sendandloadxml.php", result_xml, "GET");
};
submit_button.addEventListener("click", submitListener);
PHP Script:
<?PHP
$xml = $_GET['xm'];
echo $xml;
?>
Ok let us discuss the flash help, type the keyword "sendAndLoad" and select the same in your flash IDE and press F1, well you will read the above pasted Actionscript with few lines of code which I have added extra.
point 1 to remember if your server page doesn't recognise the data what you are sending
xm.contentType = "text/xml";
This is the reason, the data what you send is of string type you need to specify as xml type.
Point 2 to remember server side page just responds to your command and sends you the XML data, but the XML data on the flash side becomes irrelevant as it needs a parameter to accept data as string in the flash example.
result_lv.welcomeMessage;
welcomeMessage=XML should be the way you serverpage need to write data, but this is absurd, and this is nothing but string type and not XML, you will have create a new XML object to embrace this string to an XML typ, so Avoid this and try this one.
I am using the same way you load the normal XML data from a URL, all you have to do is define a new XML variable and declare most of the commands
var result_xml:XML = new XML();
result_xml.ignoreWhite = true;
result_xml.onLoad = function(s){
if(s){
result_ta.text = this.firstChild;
}else{
result_ta.text = "Error connecting to server.";
}
}
and don't specify the command result_xml.load("url") instead specify it over here
send_lv.sendAndLoad("http://vinodvv/test/sendandloadxml.php",
This should do the job. try it yourself, if you find any other better approach do make a comment.


