Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.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
String AS3在单击文本字段中的一行时调用函数_String_Actionscript 3_Function_Line_Textfield - Fatal编程技术网

String AS3在单击文本字段中的一行时调用函数

String AS3在单击文本字段中的一行时调用函数,string,actionscript-3,function,line,textfield,String,Actionscript 3,Function,Line,Textfield,单击TextField/TextArea中的一行文本时,如何调用其他函数? 我已经有了一个函数,可以在单击TextField的任意点时检索描述: list.text = "chicken"; list.addEventListener(MouseEvent.CLICK, getter); var descriptionArray:Array = new Array(); descriptionArray[0] = ["potato","chicken","lemon"];//words des

单击TextField/TextArea中的一行文本时,如何调用其他函数?

我已经有了一个函数,可以在单击TextField的任意点时检索描述:

list.text = "chicken";
list.addEventListener(MouseEvent.CLICK, getter);

var descriptionArray:Array = new Array();
descriptionArray[0] = ["potato","chicken","lemon"];//words
descriptionArray[1] = ["Round and Brown","Used to be alive","Yellow"];//descriptions

function getter(e:MouseEvent):void
{

    for (var i:int = 0; i < descriptionArray.length; i++)
    {
        var str:String = e.target.text;//The text from the list textfield
        if (str == descriptionArray[0][i]) //if the text from List is in the array
        {
            trace("found it at index: " + i);
            description.text = descriptionArray[1][i];//displays "Used to be alive".
        }
        else
        {
            trace(str+" != "+descriptionArray[0][i]);
        }
    }
}
list.text=“鸡肉”;
list.addEventListener(MouseEvent.CLICK,getter);
var descriptionArray:Array=newarray();
descriptionArray[0]=[“土豆”、“鸡肉”、“柠檬”]//话
descriptionArray[1]=[“圆形和棕色”、“曾经活着”、“黄色”]//描述
函数getter(e:MouseEvent):void
{
for(变量i:int=0;i
它工作正常,并返回正确的描述

但是我希望它根据单击文本字段/文本区域中的哪一行来检索不同的描述,比如,如果我使用
list.text=“chicken\npoto”

我知道我可以使用多个文本字段来包含每个单词,但是列表可能包含100多个单词,我想使用TextArea的滚动条来滚动列表中的单词,如果我使用多个文本字段/区域,每个字段/区域都会有自己的滚动条,这是毫无意义的

那么,如何根据单击的行调用不同的函数呢?


PS:从技术上讲,这不是一个不同的功能,它是检测单击行中的字符串,我只是这样说,以尽量减少混淆。

有一些内置方法可以让您的生活更轻松:

function getter(e:MouseEvent):void
{
    // find the line index at the clicked point
    var lineIndex:int = list.getLineIndexAtPoint(e.localX, e.localY);
    // get the text at that line index
    var itemText:String = list.getLineText(lineIndex).split("\n").join("").split("\r").join("");

    // find the text in the first array (using indexOf instead of looping)
    var itemIndex:int = descriptionArray[0].indexOf(itemText);

    // if the item was found, you can use the sam index to 
    // look up the description in the second array
    if(itemIndex != -1)
    {
        description.text = descriptionArray[1][itemIndex];
    }
}

文本字段/区域可编辑吗?不,文本字段/区域只是动态的。哇,我从来不知道这些函数存在。非常感谢,这把我从一片混乱中救了出来:)很乐意帮忙。以下是Adobe AS3参考的链接: