Hi all !

I have been wracking my brains over this seemingly simple code & issue but cannot get it to work. The code snippet, invokes a php file using URLLoader & passing 2 variables to php. The simple php file grabs a swf file, base64 encodes it and sends it back to AS3.

Code:
stop();
var rs:String ="";
var len:int = 0;
var bytes:ByteArray = new ByteArray();

var variables:URLVariables = new URLVariables();	
var varSend:URLRequest = new URLRequest("comm_1.php");
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
variables.uname = "Guest";
variables.lname = "Newbie";
variables.sendRequest = "parse";
varLoader.load(varSend);
varLoader.addEventListener(Event.COMPLETE,completeHandler);

function completeHandler(event:Event):void
{
   // SECTION 1
   //==========
    rs = event.target.data.returnString;
   len = rs.length;
	msg1.text = rs+' - '+len;
		
//	rs = "Q1dTCHAKAAB4nIVWa1RTVxbe94YbEl4CJiYg0KDCRFAQBCEd0PAQRR7lrTgCCRAExARDRLCd8WpRsSKFAlGstoro8BRGRNEZhCAJz64C4ixdylQs2hG1ZawL7VIncy6U9sqfuWvlZp/v7L3vt7+z9lk7D4gkAHY3gAkGgRaAngBcr9evY+iRWRgEhhCgyFIoN6fLZFlJO1MgR6XIBv/dKpVCTi0V8gilLCcHklJ2K5UyuSpNKd0pg+0KlcJPnhpN+WZnSfNBbQxM+PVhgY0aBxYWxXsPxX9D8bkFo5hFbeHLQQm/owbhagIMMbQRbHkaBxdQm4EhjpYzmAHGIuZlnv0eM4pXicPyGW/s/3ojHh+BnvMXhGCQ6ubz0s1nKnWNT/UanzMYZn7tkWE5UgZJpHfS60GfgEz9PkC61SFIP6qnTGoX46AEg8iw8Pysrf60l71NWCcWeh94SyailS5i+LKcZLcVu6wXPpxwF2Mhy4A1bhNVbNEJqeUkM1iJDD3bnJIAsTjEZGLoD8RorWe7MgAYIIQjFIoD/8XnQjGUMgkMtK9+fPPqxqnkniCfc/0wBz4omgrqOqtN9P1c+IKcA/+ePna5C3/yzooOFnp32+jaXM49Sen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AHWfLRNmlCm3fAfwHYQOnPh8fuffpZL18wcUTC4zkw4eAnVwCZcc0F6vvWz+KgOVJgMVL+j+aLuDwMkvGLoCB2aPrgOrSnIyNrwEnQUP9Z1WXLi6bHp0sa4k+IQHnkAgwYSU7DbKkJDhsbQaH+rVBa5p8mSuuiMGpuhMaj2XVtbS2RDc4NYY3AxxrMOfZPNnKFYP24P0MLm9X9RIkzxESEu7uilTKOiGcEGO+1qLj3HT1toQzEJtLYlVBpXFHrMXglsZCTMb/VO//MSd/5Cbn6yedd5tlQd9oCjcCVzQEwqjbcRFVtwELuE1ioSefuayPvXN1uAg4fYCFt3I9bkaG1yY8/KuXzK89JRGfsKwrroHFr/92TFlRNPr1Azg/CQTX10nYMAlsvAYcnm5p2XpS63nWHOr+SzLiTA40bnGTgLTIHJHoFQD2rMarMT1ca6Vq8lzvuzdQdLv87MotdUC4AnhVO3xXFvzFhdMpIT6w/IqYsZpTl+Mm/j5sU0eh6UYwUj9PI1GWx27O/h9H7h82txNuiwEjoeH+a9591b1BEUkWhZ1Y8CEwLsvfY3jA3qlLU32JhAsFYOyrqW2597Nqu1HudNqL2A+bLoxLoOqnxXuvO9+78m9bI+69T1yeGgz27Ki9bgcQDVJQQDaaOFSwz3IdUJ0oxnesoWaDf/kz8LG1lMVBVrM7gN06yrJdM4dxf7Py5qx1iwJnksz0ssBfkZUKXbUC91WrvAUx6TJBmEKuUOVnywQBCmW2QilVZSjkLgK/rCxBVMb2dFWOIEqWI1PmylJdQI/bU3MLSNgr0/nFr4FhVIzGltWDg9hLjDDaubx/pcmH0SR0WJrMuEXMjTQo8IOZyUbCXpHHL33wXqABChxJvmX+axiLHsYWojcbTRczowcB1LCBo8yLzhjyxWiBpi4WLGoybJu9XalZx9EABVjzdIm0GZHa/R9yOWqh";


    // SECTION 2
// =========

	var decoder:Base64Decoder = new Base64Decoder();
	decoder.decode(rs);
	var bytes:ByteArray = decoder.toByteArray();
	trace(bytes);
	trace(len);

	
}
IF I comment out section 2 of the code ( the decoding part), I can see that the string is passed just fine and displayed in a text box by
Code:
msg1.text = rs+' - '+len;
All well till here. I have pasted the actual value of string, in commented out rs string, in the code for comparison/checking purpose.

So the value of rs received from php and the value in commented out rs string are same.

Now if I un-comment section 2, which tries to base64 decode the string back, I immediately get the following error:

Error
at Base64Decoder/flush()
at Base64Decoder/toByteArray()
at AS3_swf_php_comm_1_fla::MainTimeline/completeHandler()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunctio n()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/flash.net:URLLoader:nComplete()
The php code is as below:

PHP Code:
if($_POST[‘sendRequest’] ===“parse”){

var_dump($_POST);

$uname $_POST[‘uname’];
$lname $_POST[‘lname’];

$p file_get_contents(‘dummy.swf’);
$p base64_encode($p);
echo 
&returnString=.$p;
exit;

I have been trying to figure this out for a long time without success. Please someone enlighten me what am I doing wrong and what is it that I need to do to get this working.

Thanks to all !!