Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/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 如何将文本框值推入数组并调用它_Actionscript 3 - Fatal编程技术网

Actionscript 3 如何将文本框值推入数组并调用它

Actionscript 3 如何将文本框值推入数组并调用它,actionscript-3,Actionscript 3,这是我第一次在这个网站上询问,如果有任何错误和不适当的事情,请提前道歉 我试着用动作脚本3制作我自己的篮球记分板,但是我被困在了一个叫球员犯规记分并单独展示的路上 在图片中,第二个框是输入犯规球员编号的地方,第三个框是数字显示该球员犯规次数的地方。 我需要知道如何编码一个数组存储区,该存储区从“玩家”文本框接收一个值作为玩家编号,并将犯规计数与特定玩家编号一起存储(如果我键入另一个玩家编号,它将单独计算犯规,下次我键入exist编号时,它将显示他犯规的次数)您可以使用数组、字典,甚至动态属性

这是我第一次在这个网站上询问,如果有任何错误和不适当的事情,请提前道歉

我试着用动作脚本3制作我自己的篮球记分板,但是我被困在了一个叫球员犯规记分并单独展示的路上

在图片中,第二个框是输入犯规球员编号的地方,第三个框是数字显示该球员犯规次数的地方。


我需要知道如何编码一个数组存储区,该存储区从“玩家”文本框接收一个值作为玩家编号,并将犯规计数与特定玩家编号一起存储(如果我键入另一个玩家编号,它将单独计算犯规,下次我键入exist编号时,它将显示他犯规的次数)您可以使用数组、字典,甚至动态属性

假设您的文本字段被称为
txtTeam1fouls
txtPlayer
txtFouls
txtTeam2fouls
。我们还假设您有一个名为
curTeam
的变量,该变量存储您输入其球员编号的球队的整数标识符(例如
1
,或
2

以下是在数组中存储基本对象的示例:

var fouls:Array = []; //create a new empty array

//add a listener for when you type something into the player text input
txtPlayer.addEventListener(KeyboardEvent.KEY_UP, updatePlayer);

//this function retries a foul record from the array for a specific player
function getFouls(player:int, teamId:int):Object {
    //loop through the array until you find a match
    for(var i:int=0;i<fouls.length;i++){
        if(fouls[i].player === player && fouls[i].team === teamId){
            return fouls[i];
        }
    }
    //if no record in the array, return 0
    return null;
}

//this function updates the foul text field when you change the what's in the player text field
function updatePlayer(e:Event):void {
    var foulRecord = getFouls(int(txtPlayer.text), curTeam); 
    //if a foul record exists, use it's foul count, if not use 0
    txtFouls.text = foulRecord ? foulRecord.fouls.toString() : 0;
}

//call this function whenever you add a new foul record. 
function addFoul(player:int, teamId:int):void {

    //first, see if there is an existing foul record in the array
    var foulObj:Object = getFouls(player, teamId);

    if(!foulObj){
        //if there was no record, create one, then push (add) it to the array
        foulObj = {team: teamId, player: player, fouls: 1};
        fouls.push(foulObj);
    }else{
        //if there is an existing record, increment it.
        foulObj.fouls++;
    }

    //now update the totals for each team
    var team1Ctr:int = 0;
    var team2Ctr:int = 0;

    for(var i:int=0;i<fouls.length;i++){
        switch(fouls[i].team){
            case 1:
                team1Ctr++;
                break;

            case 2:
                team2Ctr++;
                break;
        }
    }

    txtTeam1Fouls.text = team1Ctr.toString();
    txtTeam2Fouls.text = team2Ctr.toString();
}
var犯规:数组=[]//创建一个新的空数组
//在播放器文本输入中键入内容时为添加侦听器
txtPlayer.addEventListener(KeyboardEvent.KEY\u UP,updatePlayer);
//此函数用于从阵列中为特定玩家重试犯规记录
函数getFouls(玩家:int,团队ID:int):对象{
//在数组中循环,直到找到匹配项

对于(var i:int=0;i您可以像任何其他对象一样将文本字段推送到数组:
array.push(textfield);
…非常感谢您的建议,先生。