单击它时试图隐藏数组中的对象,没有数组但没有? Actionscript 3.0

时间:2021-07-23 21:37:14

I am making a little game and I have an array. The array contains 4 characters. When one of the characters is clicked the opacity should turn to 0, if another is clicked the same should also happen.

我正在做一个小游戏,我有一个阵列。该数组包含4个字符。单击其中一个字符时,不透明度应该变为0,如果单击另一个字符,则也应该发生相同的情况。

So far I have put the array into a function but the function will only hide one of the characters, and not even the one which is clicked. Could anyone help me please? Here is the code I have:

到目前为止,我已将数组放入一个函数中,但该函数只会隐藏其中一个字符,甚至不会隐藏一个字符。有人可以帮我吗?这是我的代码:

for(var g:int = 0; g<ghostsL.length; g++){
ghostsL[g].addEventListener(MouseEvent.CLICK, clickGrey)
};
function clickGrey(e:MouseEvent):void{
        this.ghostsL[i].alpha = 0;
        var npoint:NPoint = new NPoint();
        npoint.play();
        };

1 个解决方案

#1


2  

We do not know what this.ghostsL[i] is.

我们不知道this.ghostsL [i]是什么。

Why don't you just do it this way:

你为什么不这样做:

function clickGrey(e:MouseEvent):void{
        MovieClip(e.currentTarget).alpha = 0;
        var npoint:NPoint = new NPoint();
        npoint.play();
};

#1


2  

We do not know what this.ghostsL[i] is.

我们不知道this.ghostsL [i]是什么。

Why don't you just do it this way:

你为什么不这样做:

function clickGrey(e:MouseEvent):void{
        MovieClip(e.currentTarget).alpha = 0;
        var npoint:NPoint = new NPoint();
        npoint.play();
};