View Single Post
Nutrox's Avatar Nutrox Nutrox is offline Super Moderator 17 Creative Assets 2008-11-11 #6 Old  
Ideally you will know what format the incoming data is using, the service you are using should have that in their API docs or allow you to request a specific format using header information. You can load any data as binary though (it gets pushed into a byte array) so you could try something like this...

Code:
var req:URLRequest = new URLRequest();
// setup your request here

var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.load( req );
loader.addEventListener( Event.COMPLETE, dataHandler );

function dataHandler( e:Event ):void
{
	var data:ByteArray = loader.data;
	
	try
	{
		// attempt to decompress the data
		data.uncompress();
	}
	catch( err:Error )
	{
		try
		{
			// attempt to decompress the data again
			data.uncompress( CompressionAlgorithm.DEFLATE );
		}
		catch( err:Error )
		{}
	}
	
	// grab the text from the byte array
	var text:String = data.readUTFBytes( data.length );
	
	// you should now be able to create your XML object
	var xml:XML = new XML( text );
	
	// keep things tidy
	loader.data.length = 0;
	loader.data = null;
	loader.removeEventListener( Event.COMPLETE, dataHandler );
}
Reply With Quote