Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 匹配文本文件和用户输入中的两个字符串?(AS3)_Actionscript 3 - Fatal编程技术网

Actionscript 3 匹配文本文件和用户输入中的两个字符串?(AS3)

Actionscript 3 匹配文本文件和用户输入中的两个字符串?(AS3),actionscript-3,Actionscript 3,我可以在Flash文件中加载一个文本文件,但无法匹配文本文件和用户输入中的两个字符串 此AS3代码的目的是:匹配文本文件和用户输入,如果匹配,分数将增加1。否则,分数将增加0 这是我的密码: var uScore :Number = 0; stop(); var textLoader:URLLoader = new URLLoader(); var textURLRequest:URLRequest = new URLRequest("q1.txt"); textLoader.addEve

我可以在Flash文件中加载一个文本文件,但无法匹配文本文件和用户输入中的两个字符串

此AS3代码的目的是:匹配文本文件和用户输入,如果匹配,分数将增加1。否则,分数将增加0

这是我的密码:

var uScore :Number = 0;

stop();

var textLoader:URLLoader = new URLLoader();
var textURLRequest:URLRequest = new URLRequest("q1.txt");

textLoader.addEventListener(Event.COMPLETE, completeHandler);

function completeHandler(event:Event):void
{
    var textData:String = new String(textLoader.data);
    dy1.text = textData;
}

textLoader.load(textURLRequest);




function goURL(event:MouseEvent):void {

var textLoader2:URLLoader = new URLLoader();
var textURLRequest2:URLRequest = new URLRequest("answer1.txt");

    var textData2:String = new String(textLoader2.data);
    var name1 = trace(textData2);


textLoader2.load(textURLRequest2);

    var myURL = url1.text;
    if(myURL == name1){
        uScore += 1;
        uScoreURL.text = uScore+"";
        nextFrame();
    }
    else{
        uScore+=0;
        uScoreURL.text = uScore+"";
        nextFrame();
    }
}

        trace(uScore);

您的代码有一个奇怪的赋值:

var name1 = trace(textData2);
换成

var name1 =textData2;
如果在其他地方没有bug,它应该可以工作


您不需要
uScore+=0。删除它。

我检查了你的代码,你做了一些不正常的事情-这是修改后的代码,应该可以让你达到你需要的地方

var uScore :Number = 0;

stop();

var textLoader:URLLoader = new URLLoader();
var textURLRequest:URLRequest = new URLRequest("q1.txt");

textLoader.addEventListener(Event.COMPLETE, completeHandler);

function completeHandler(event:Event):void
{
    var textData:String = new String(textLoader.data);
    dy1.text = textData;
}

textLoader.load(textURLRequest);

btn.addEventListener(MouseEvent.CLICK,getNumber);

var textLoader2:URLLoader = new URLLoader();
textLoader2.addEventListener(Event.COMPLETE, completeHandler2);

function completeHandler2(event:Event):void
{
   var textData2:String = new String(textLoader2.data);
    var name1 = textData2;
    trace(name1);

    var myURL = url1.text;
    if(myURL == name1){
        uScore += 1;
        uScoreURL.text = uScore+"";
        nextFrame();
    }
    else{
        uScore+=0;
        uScoreURL.text = uScore+"";
        nextFrame();
    }
}

function getNumber(event:MouseEvent){
    var textURLRequest2:URLRequest = new URLRequest("answer1.txt");

    textLoader2.load(textURLRequest2);
}

        trace(uScore);

我真正添加的唯一一件事是,您没有一个带有变量名的按钮来检查答案-您可以将其修改为您想要检查答案的任何形式。

谢谢您的回复。不幸的是,替换该语句仍然不起作用。如果(myURL==name1)将跟踪(myURL,name1)放在前面一行进行比较,您将知道某个字符串是否为null或“未定义”。