使用变量A来控制变量B.

时间:2014-03-29 01:34:56

标签: arrays actionscript-3 function variables

我有一个名为FarmClick的函数,我希望它检查当前的MovieClip数组。例如:

var farmSpot1:("id",int,int);
var farmSpot2...

我需要clickEvent来捕获MovieClips名称并检查第0个元素的数组以查看它是否为空,或者不是...... 到目前为止我的代码:

 public function FarmClick(event: MouseEvent): void {
        var CurrentSlot = event.currentTarget.name
            if ([event.currentTarget.name[0]] = "empty") {
            stage.addChild(menu);
            menu.x = 400;
                menu.y = 90;
            this.menu.buyCornBtn2.addEventListener(MouseEvent.CLICK,buyCorn2);
        } else if (farmEmpty == true && itemSelected != "none") {
            selected();
        } else if (farmEmpty == false) {
            farmHarvest();
        }
    }

1 个答案:

答案 0 :(得分:0)

我花了一分钟才弄明白你究竟是在问什么。 所以基本上,你的影片剪辑名称是farmSpot[someNumber],你有一个同名的数组?

在这种情况下,要引用数组变量,您需要使用this关键字。

你可以在引用它之后添加任何数组下标:

private var farmSpot1:Array = ["id", int, int];

public function FarmClick(event:MouseEvent): void 
{
     if (this[event.currentTarget.name][0] == "") // wasnt sure if you meant the string "empty" or just an empty string, so i just put an empty string
     {
          // do whatevs
     }
}