dsq2015 2014-05-15 05:24
浏览 32
已采纳

too long

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            
}
  • 写回答

1条回答 默认 最新

  • douli0531 2014-05-15 05:50
    关注

    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
    ]*/gim;
    itWorked = itWorked.replace(rex,'');
    if (itWorked == "success")
    {
    // Now it works. I hope this helps someone. 
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用