flash AS3 if/else 语句的问题

发布于 2024-12-05 19:32:45 字数 3231 浏览 0 评论 0原文

我试图在 flash 中使用 if 语句来检查变量(从 PHP 获取)是否等于某个值,但是出了问题。

代码:

function completeHandler(event:Event):void{
    // Load the response from the PHP file
    var data:URLVariables = new URLVariables(event.target.data);
    var return_stat = data.return_stat_verify;



    if (return_stat == "FAILED"){
    status_txt.text = "dsfdsfg";
        }
        else if (return_stat == "PASSED"){

        var first_nme = data.return_first;
        var second_nme = data.return_second;
    var email_addr = data.return_email;
    var user_domain = data.return_domain;
    var user_name = data.return_username;

    gotoAndPlay("finish");

    first_txt.text = first_nme;
    second_txt.text = second_nme;
    email_txt.text =  email_addr;
    username_txt.text = user_name;
    domain_txt.text = user_domain;


    }

现在当我测试时,什么也没有发生。然后,我尝试在其中放置一个简单的 else 语句,以查看 ifelse if 语句是否都失败。

代码:

function completeHandler(event:Event):void{
    // Load the response from the PHP file
    var data:URLVariables = new URLVariables(event.target.data);
    var return_stat = data.return_stat_verify;

    if (return_stat == "FAILED"){
    status_txt.text = "dsfdsfg";
    }
    else if (return_stat == "PASSED"){

    var first_nme = data.return_first;
    var second_nme = data.return_second;
    var email_addr = data.return_email;
    var user_domain = data.return_domain;
    var user_name = data.return_username;

    gotoAndPlay("finish");

    first_txt.text = first_nme;
    second_txt.text = second_nme;
    email_txt.text =  email_addr;
    username_txt.text = user_name;
    domain_txt.text = user_domain;


    }
    else {
        status_txt.text = "I hate flash";

    }

现在,当我测试时,flash 在 status_txt 字段中打印出“我讨厌 flash”。因此,我然后替换 status_txt 的值以打印出我正在使用 if 语句的变量 (return_stat):

else {
            status_txt.text = return_stat;

        }

然后,当我测试它时,它显示 PASSED或失败。这意味着问题不在于 PHP,因为它返回了正确的数据,而问题在于 If 语句中。

我完全迷失在这里了。我没有看到我做错了什么,有什么想法吗?

谢谢你们。

编辑

我的PHP代码:

<?php

require ('installation_5_functions.php');
require ('cust_ver_i.php');


$username=$_POST['userName'];

$ident_encrypt=$_POST['userPsswrd'];


verify($reference_id, $username, $ident_encrypt);


if ($ref_id_stat == "FAILED"){

$retrn_stat = "FAILED";

print "return_value=$error_ref_id&return_stat_verify=$retrn_stat";  

exit();

}
if($ref_id_stat == "PASSED"){

if ($user_verify_status == "FAILED"){

$retrn_stat = "FAILED";


print "return_value=$user_verify_error&return_stat_verify=$retrn_stat";

}

elseif ($user_verify_status == "PASSED"){

if ($cust_status == "DEACT"){

$retrn_stat = "FAILED";

print "return_value=$display_error_stat&return_stat_verify=$retrn_stat";    

}
elseif ($cust_status == "ACTIVE"){

$retrn_stat = "PASSED"; 

print "return_first=$cust_first&return_second=$cust_last&return_email=$cust_email&return_username=$cust_username&return_domain=$cust_domain&return_stat_verify=$retrn_stat";

}

}
}



?>

I'm trying to use the if statement in flash to check if a variable (fetched from PHP) is equal to something, but something is going wrong.

The code:

function completeHandler(event:Event):void{
    // Load the response from the PHP file
    var data:URLVariables = new URLVariables(event.target.data);
    var return_stat = data.return_stat_verify;



    if (return_stat == "FAILED"){
    status_txt.text = "dsfdsfg";
        }
        else if (return_stat == "PASSED"){

        var first_nme = data.return_first;
        var second_nme = data.return_second;
    var email_addr = data.return_email;
    var user_domain = data.return_domain;
    var user_name = data.return_username;

    gotoAndPlay("finish");

    first_txt.text = first_nme;
    second_txt.text = second_nme;
    email_txt.text =  email_addr;
    username_txt.text = user_name;
    domain_txt.text = user_domain;


    }

Now when i test that, nothing happens. I then make an attempt to place a simple else statement in there to see if both if and else if statements fail.

the code:

function completeHandler(event:Event):void{
    // Load the response from the PHP file
    var data:URLVariables = new URLVariables(event.target.data);
    var return_stat = data.return_stat_verify;

    if (return_stat == "FAILED"){
    status_txt.text = "dsfdsfg";
    }
    else if (return_stat == "PASSED"){

    var first_nme = data.return_first;
    var second_nme = data.return_second;
    var email_addr = data.return_email;
    var user_domain = data.return_domain;
    var user_name = data.return_username;

    gotoAndPlay("finish");

    first_txt.text = first_nme;
    second_txt.text = second_nme;
    email_txt.text =  email_addr;
    username_txt.text = user_name;
    domain_txt.text = user_domain;


    }
    else {
        status_txt.text = "I hate flash";

    }

Now when i test that, flash prints out "I hate flash" in the status_txt field. So i then replace the value of status_txt to print out the variable that I'm using the if statements with (return_stat):

else {
            status_txt.text = return_stat;

        }

Then when i test it, it shows either PASSED or FAILED. Which means the issue does not lie in PHP as it's returning the correct data and the issue lies within the If statements.

I'm completely lost here. I don't see anything that I've done wrong, any ideas?

Thanks guys.

EDIT

My PHP CODE:

<?php

require ('installation_5_functions.php');
require ('cust_ver_i.php');


$username=$_POST['userName'];

$ident_encrypt=$_POST['userPsswrd'];


verify($reference_id, $username, $ident_encrypt);


if ($ref_id_stat == "FAILED"){

$retrn_stat = "FAILED";

print "return_value=$error_ref_id&return_stat_verify=$retrn_stat";  

exit();

}
if($ref_id_stat == "PASSED"){

if ($user_verify_status == "FAILED"){

$retrn_stat = "FAILED";


print "return_value=$user_verify_error&return_stat_verify=$retrn_stat";

}

elseif ($user_verify_status == "PASSED"){

if ($cust_status == "DEACT"){

$retrn_stat = "FAILED";

print "return_value=$display_error_stat&return_stat_verify=$retrn_stat";    

}
elseif ($cust_status == "ACTIVE"){

$retrn_stat = "PASSED"; 

print "return_first=$cust_first&return_second=$cust_last&return_email=$cust_email&return_username=$cust_username&return_domain=$cust_domain&return_stat_verify=$retrn_stat";

}

}
}



?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

阪姬 2024-12-12 19:32:45

很多时候,空白可能会出现问题。例如,如果

data.return_stat_verify == 'FAILED  '

将其放入 TextField 中,则不会出现任何差异。要查看是否是这种情况,您可以尝试:

// place a character on both sides. That will show whether there is whitespace
status_txt.text = "|"+return_stat+"|";

编辑

它看起来像下面的情况。这意味着您需要修剪您的输入。首先,确保 PHP 文件中没有多余的空格(最后一行是否为 ?> 或者末尾是否有空行?空行,在 ?> 会导致您描述的问题。

然后,为了安全起见,我个人也会使用 StringUtil.trim 因为它是最明确的,并且因为大多数语言都有一些方法来做一些非常相似的事情,如果做不到这一点,我会使用正则表达式来解决这个问题:

// using two to be explicit
// /^\s+/m this removes all occurrences of one or more spaces at the beginning
return_stat = return_stat.replace(/^\s+/m, "");
// /\s+$/m this removes all occurrences of one or more spaces at the end
return_stat = return_stat.replace(/\s+$/m, "");

当然,你可以直接内嵌它:

// use the global flag if you are doing this all at once.
return_stat = return_stat.replace(/^\s+|\s+$/mg, "");

A lot of times there can be issues with whitespace. For example, if

data.return_stat_verify == 'FAILED  '

When you put it into a TextField, there will not appear to be a difference. To see if this is the case, you might try:

// place a character on both sides. That will show whether there is whitespace
status_txt.text = "|"+return_stat+"|";

EDIT

It looks like this is the case below. This means you need to trim your input. First, make sure that there is no extra whitespace in the PHP file (do you have the last line as ?> or is there an empty line at the end? An empty line, outside of ?> would cause the problem you describe.

Then, for safety's sake, check the input as well. Personally, I would use StringUtil.trim because it is the most explicit and because most languages have some way to do something very similar. Failing that, I would use regex to fix this:

// using two to be explicit
// /^\s+/m this removes all occurrences of one or more spaces at the beginning
return_stat = return_stat.replace(/^\s+/m, "");
// /\s+$/m this removes all occurrences of one or more spaces at the end
return_stat = return_stat.replace(/\s+$/m, "");

Of course, you could just in-line it:

// use the global flag if you are doing this all at once.
return_stat = return_stat.replace(/^\s+|\s+$/mg, "");
深爱成瘾 2024-12-12 19:32:45

好吧,我已经成功解决了这个问题。我将 exit(); 放在 php 脚本中每个 if/else 语句的底部,它现在似乎可以正常工作。毫无意义,但它确实达到了目的。

感谢您的帮助。

Ok, I've managed to solve the problem. I placed exit(); at the bottom of every if/else statement in the php script and it seems to be working now. Makes no sense what so ever but it did the trick.

Thanks for your help.

我的黑色迷你裙 2024-12-12 19:32:45

该问题可能是由结束 php 标签引起的:?>
请参阅: 为什么要省略结束标记?

该标记后面的任何空格都将附加到任何 print/回声输出。虽然 html 页面中的额外空格不会造成问题,但在您的情况下这是一个问题。很容易错过这一点,因此最好避免在这些情况下使用结束标签,或者真正确保标签后面没有任何字符。

The problem could be caused by the closing php tag: ?>
See: Why would one omit the close tag?

Any whitespace after that tag would be appended to any print/echo output. While additional whitespace in a html page wouldn't cause trouble, in your case it's a problem. It is easy to miss that, so it's best to avoid using the closing tag in those cases or to really make sure there aren't any characters after the tag.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文