Groups | Blog | Home
all groups > flash data integration > may 2005 >

flash data integration : object array to xml


andros
5/7/2005 12:00:00 AM
I have an array that contains objects ie:
{id:3, t_name:"first"}

I am ultimately trying to output this as an xml.
Currently I can send an array from flash to a php script and assemble an XML
file successfully.
But as soon as I try to send an array with objects in it...the php script
cannot parse the string back into an objectArray.
Now , i realize there might be an option in PHP to do this..but I think the
problem lies in how flash sends the array.
I cannot seem to print_r in php and look at the array either.

Optionally, is there a way to send the array as some sort of XML packet all
ready for XML creation in the PHP script?

Any leads would be much appreciated.
LuigiL
5/8/2005 12:00:00 AM
Maybe this tutorial helps:
Patrick Bay
5/9/2005 2:38:37 PM
Hi Andros,

Converting a unidemnsional array is fairly straigntforward:

var myXML:XML=new XML('<array/>');
var myArray:Object={id:3, t_name:"first"};
for (var item in myArray) {
myXML.firstChild.attributes[item]=myArray[item];
}

This creates an XML object with a long string of attributes. In this case, it
will look like this:

<array id="3" t_name="first"/>

You can now pass this to the PHP script using the sendAndLoad command. Some
things to watch out for when doing this, however:

1. Set the content-type of the XML object:

myXML.contentType='text/xml';

2. The receiving PHP script must read the raw HTTP post data. No other data will
be available to the script:

$rawXMLData=urldecode($HTTP_RAW_POST_DATA);

3. The PHP script will receive this as a string. If you want to work with it as
XML (a multi-dimensional array), you'll need to use a function like
'xml_parse_into_struct'. Personally, I find PHP handling of XML rather clunky
but it's better than raw text so give it a try.

Regards,
Patrick

[quoted text, click to view]
AddThis Social Bookmark Button