ANSWER: Issue was with PHP
-- You must return a var to AS3 or you will get this error.
I am posting this because unless the viewer reads the comments they will not know what the issue was and a solution. Anil, who asked this question stated it was an issue with the PHP and not as3 but gave no reason as to why. It seems the answer marked correct above is not a sufficient answer because it only suggests a possible solution. Where Anil, admitted it was an issue with the php. I believe this answer is more complete and can help someone who has this same issue.
I had a similar issue. The problem was with the php. Unless you output something back from the php you will get this error.
Flash did not like nothing being returned from php and gave the following error:
Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
at Error$/throwError()
at flash.net::URLVariables/decode()
at flash.net::URLVariables()
at flash.net::URLLoader/onComplete()
Here was a part of my PHP that did not return anything:
if($ConfirmedEmail=="true")
{
echo "Status=true";
}
if($ConfirmedEmail=="false")
{
echo "Status=false";
}
But if it was neither true/false it would OUTPUT NOTHING. = Flash Does Not Like!
So the PHP code had to be this:
if($ConfirmedEmail=="true")
{
echo "Status=true";
}
else if($ConfirmedEmail=="false")
{
echo "Status=false";
}
else
{
echo "Status=Nada";
}
Here is my AS3 code for you to look at. Hope it helps someone.
public function checkEmail(e:Event = null)
{
var urlreq = new URLRequest("http://www.MyWebsite.com/myScript.php");
urlreq.method = URLRequestMethod.POST;
var urlvars = new URLVariables();
urlvars.userID = Main.userID;
urlreq.data = urlvars;
var loader:URLLoader = new URLLoader(urlreq);
loader.addEventListener(Event.COMPLETE, completed);
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.load(urlreq);
}
public function completed(event:Event):void
{
var variables:URLVariables = new URLVariables(event.target.data);
trace("Email Confirmed: " + variables.Status);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…