As3 if语句不工作(从php加载var)


as3 if statement not working (var loaded from php)

更新:答案如下!

我正在调用一个php脚本从一个移动设备编码在as3为空气。php脚本工作得很好,并将正确的var发送回as3。我得到了正确的跟踪语句,但是if语句不起作用。

下面是php代码行:

echo "done=success";

下面是as3代码

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            
}

留白!

我发现答案是php或as3在末尾添加的额外空白。它不能在跟踪语句中看到。我发现了这一点,因为我复制了跟踪语句,并注意到有一个额外的空白,我可以突出显示。

简而言之,在跟踪语句中看起来像单词"success"(没有引号),实际上是var"success"加上一个额外的空白。因此,if语句不能将其视为"成功",因为它确实是"成功"。

为了解决这个问题,我使用了以下代码:
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. 
}