AS2多个按钮阵列共享相同的操作以及单个操作

时间:2014-11-13 18:38:51

标签: arrays actionscript actionscript-2

我有5个按钮mcs,它们共享相同的rollOver / rollOut函数。但是,它们也都对rollOver有特定的操作,例如mc1也会在rollOver上执行以下操作:

TweenLite.to(tips_mc.tip1, 1, { _alpha:100 });

我如何才能在数组中的rollOver上为每个mc添加每个单独的调用?

我的数组如下:

var btnArray:Array = new Array(mc1, mc2, mc3, mc4, mc5);
for (i=0; i<btnArray.length; i++) {
///initial state///
btnArray[i].enabled = true;
btnArray[i].id = i;
btnArray[i].onRollOver = function() {
    this.gotoAndPlay("over");
};
btnArray[i].onRollOut = function() {
    this.gotoAndPlay("out");
};

}

任何帮助非常感谢!谢谢!

1 个答案:

答案 0 :(得分:0)

您可以在不同的functions中编写您的操作,并按照以下方式调用它们:

var functionsArray:Array /* of Function */ = [f1, f2, f3, f4, f5]; 
var btnArray:Array /* of MovieClip */ = [mc1, mc2, mc3, mc4, mc5];
var l:Number = btnArray.length;

for (var i:Number = 0; i < l; i++)
{
    btnArray[i].enabled = true;
    btnArray[i].id = i;
    btnArray[i].onRollOver = function()
    {
        functionsArray[this.id](); // you invoke your function here 
        this.gotoAndPlay("over");
    }
    btnArray[i].onRollOut = function()
    {
        this.gotoAndPlay("out");
    }
}

function f1():Void {trace("I'm the function 1");}
function f2():Void {trace("I'm the function 2");}
function f3():Void {trace("I'm the function 3");}
function f4():Void {trace("I'm the function 4");}
function f5():Void {trace("I'm the function 5");}