UPDATE: Answered Below!

I am calling a php script from a mobile device coded in as3 for Air. The php script works great and sends the right var back to as3. I get the correct trace statement but the if statement is not working.

Here is the php line:

echo "done=success";

Here is the as3 code

var variables:URLVariables = new URLVariables(event.target.data);
trace(variables.done); // WORKS echos out: success

// So I figured this line should work too, but it doesn't. Any ideas why?           

if(variables.done=="success")
{
// Does not work            
}
有帮助吗?

解决方案

WHITE SPACE!

I found out the answer was an extra white space that php or as3 was adding in at the end. It could not be seen in the trace statement. I figured this out because I copied the trace statement and noticed there was an extra white space that I could highlight.

In short what looked like the word "success" (without the quotes) in a trace statement, was really the var "success " with an extra white space. Thus the if statement could not see it as "success" because it was really "success ".

To fix it I used this code:

var variables:URLVariables = new URLVariables(event.target.data);
trace(variables.done);

var itWorked:String = variables.done;
var rex:RegExp = /[\s\r\n]*/gim;
itWorked = itWorked.replace(rex,'');
if (itWorked == "success")
{
// Now it works. I hope this helps someone. 
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top