【问题标题】:flash If statement only working on the second timeflash If 语句仅在第二次起作用
【发布时间】:2012-11-02 13:27:03
【问题描述】:

我正在做一个页面来检查输入的答案,并根据响应说“正确”或“错误”。问题是它只能在第二次使用。

我问了一个关于第二次世界大战的问题,答案是“hiroshima”,没有大写字母,但是当我第一次输入时,如果我再次输入,我会得到“错误”,它说它是正确的。

对我做错了什么有任何想法吗?

这是我的代码,由按钮上的偶数侦听器触发。

function examineTest(event:Event) : void{

    if (testPage.answerText.text=='hiroshima')
    {
        testPage.checkText.text="Correct!"
    }

    else

    {
        testPage.checkText.text="Sorry you enter the wrong answer"
        testPage.answerText.text=""
    }
}

【问题讨论】:

  • answerText.text 中是否有一些可能隐藏的文本在您执行 testPage.answerText.text="" 之前不会被删除?在用户有机会输入文本之前尝试将其设置为 ""
  • 嗨,谢谢您的回复。我做到了(至少我认为我做到了),当回到文本框并寻找任何空格或任何东西时,那里什么也没有。我仍然得到同样的错误。我确实添加了一些新代码来解释大写字母。但问题仍然存在。函数检查测试(事件:事件):无效{ testPage.answerText.text="" if ((testPage.answerText.text.toLowerCase()=='hiroshima')) { testPage.checkText.text="Correct!" } else { testPage.checkText.text="对不起,你输入了错误的答案" testPage.answerText.text="" } }
  • 尝试testPage.answerText.text.toLowerCase().lastIndexOf('hiroshima') == 0 以获得更好的字符串比较。我想你也可以查看length
  • 当然,如果你这样做:function examineTest(event:Event) : void{ testPage.answerText.text="" if ((testPage.ans... 在比较之前你只是将它设置为"",我认为它总是错误的。
  • 您的代码有效 (testPage.answerText.text.toLowerCase().lastIndexOf('hiroshima') == 0) 非常感谢......这让我整天发疯,找不到任何答案.再次感谢:)

标签: actionscript flash-cs5


【解决方案1】:

试试

testPage.answerText.text.toLowerCase().lastIndexOf('hiroshima') == 0

为了更好的字符串比较。

但是,这并不能保证字符串完全匹配。因为最后可能会有额外的字符。因为您知道hiroshima 的长度为 9 个字符。然后你也可以查看length

testPage.answerText.text.length == 9

http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00001559.html 这个网站是你最好的资源

【讨论】:

    猜你喜欢
    • 2018-09-26
    • 1970-01-01
    • 2016-01-03
    • 1970-01-01
    • 2018-10-01
    • 1970-01-01
    • 2017-05-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多