I am sending some information from PHP to flash, and sending some different information from PHP back to flash. I'm sending a user ID to PHP, and sending an XML variable, as well as an index, back to Flash.
Flash code:
var myLoader:URLLoader = new URLLoader();
var myRequest:URLRequest = new URLRequest(/*private info*/);
myRequest.method = URLRequestMethod.POST;
var memberInfo:URLVariables = new URLVariables();
memberInfo.member_id = 1817;
myRequest.data = memberInfo;
myLoader.addEventListener(Event.COMPLETE, onXMLLoad);
myLoader.load(myRequest);
function onXMLLoad(event:Event)
{
var newXML:XML = new XML(event.currentTarget.data.xml);
var index:int = new int(event.currentTarget.data.index);
}
PHP:
$xml = new DOMDocument("1.0");
$xml->formatOutput = true;
$xml->preserveWhiteSpace = false;
$presets = $xml->createElement("presets");
$red = $xml->createElement("colors", "0xff0000");
$green = $xml->createElement("colors", "0x00ff00");
$blue = $xml->createElement("colors", "0x0000ff");
$presets->appendChild($red);
$presets->appendChild($green);
$presets->appendChild($blue);
$xml->appendChild($presets);
$index = 3;
echo $xml->saveXML();
echo $index;
When I do this, I get this error:
ReferenceError: Error #1069: Property xml not found on String and there is no default value.
How can I fix this? I'm thinking it has something to do with the XML actually being a string, but I'm not quite sure.
Here is the output from PHP:
<?xml version="1.0"?>
<presets>
<colors>0xff0000</colors>
<colors>0x00ff00</colors>
<colors>0x0000ff</colors>
</presets> 3
Note: If I delete the index variable from PHP and just have "xml" as the only thing being sent to Flash, I can access it using "event.currentTarget.data" and it will work fine.
Flash:
var myLoader:URLLoader = new URLLoader();
var myRequest:URLRequest = new URLRequest(/*private info*/);
myRequest.method = URLRequestMethod.POST;
var memberInfo:URLVariables = new URLVariables();
memberInfo.member_id = 1817;
myRequest.data = memberInfo;
myLoader.addEventListener(Event.COMPLETE, onXMLLoad);
myLoader.load(myRequest);
function onXMLLoad(event:Event)
{
var newXML:XML = new XML(event.currentTarget.data);
}
PHP:
$xml = new DOMDocument("1.0");
$xml->formatOutput = true;
$xml->preserveWhiteSpace = false;
$presets = $xml->createElement("presets");
$red = $xml->createElement("colors", "0xff0000");
$green = $xml->createElement("colors", "0x00ff00");
$blue = $xml->createElement("colors", "0x0000ff");
$presets->appendChild($red);
$presets->appendChild($green);
$presets->appendChild($blue);
$xml->appendChild($presets);
echo $xml->saveXML();
header( "content-type: application/xml; charset=ISO-8859-15" );<xml></xml>3, which is not valid xml and does not have anxmlurl parameter as AS3 is expecting something like this:xml=<xml></xml>&index=3event.currentTarget.data, andxmlis the only thing being echoed, the xml is outputted and well-formatted in flash.<?xml version="1.0"?> <presets> <colors>0xff0000</colors> <colors>0x00ff00</colors> <colors>0x0000ff</colors> </presets> 3' is what is outputted when I use .TEXT. When I create a new set of URLVariables inside my onComplete function, and access the.xml` property of the new URLVariables, I get null as my output. (Sorry, the xml in my comment is well-formed in the output)