如何将此代码更改为数组?

时间:2010-01-19 21:58:00

标签: flash

任何建议都将不胜感激

tocProduction.alpha = 0;
tocWardrobe.alpha = 0;
tocMakeup.alpha = 0;
tocIllustrators.alpha = 0;
tocSpecialfx.alpha = 0;
tocAssisting.alpha = 0;
tocContact.alpha = 0;

tocProduction.x = 400;
tocWardrobe.x = 400;
tocMakeup.x = 400;
tocIllustrators.x = 400;
tocSpecialfx.x = 400;
tocAssisting.x = 400;
tocContact.x = 400;

TweenMax.to(tocProduction, .75, {alpha:1, ease:Circ.easeIn});
TweenMax.to(tocWardrobe, 1, {alpha:1, ease:Circ.easeIn});
TweenMax.to(tocMakeup, 1.25, {alpha:1, ease:Circ.easeIn});
TweenMax.to(tocIllustrators, 1.5, {alpha:1, ease:Circ.easeIn});
TweenMax.to(tocSpecialfx, 1.75, {alpha:1, ease:Circ.easeIn});
TweenMax.to(tocAssisting, 2, {alpha:1, ease:Circ.easeIn});
TweenMax.to(tocContact, 2.25, {alpha:1, ease:Circ.easeIn});

tocProduction.addEventListener(MouseEvent.MOUSE_OVER, over);
tocWardrobe.addEventListener(MouseEvent.MOUSE_OVER, over1);
tocMakeup.addEventListener(MouseEvent.MOUSE_OVER, over2);
tocIllustrators.addEventListener(MouseEvent.MOUSE_OVER, over3);
tocSpecialfx.addEventListener(MouseEvent.MOUSE_OVER, over4);
tocAssisting.addEventListener(MouseEvent.MOUSE_OVER, over5);
tocContact.addEventListener(MouseEvent.MOUSE_OVER, over6);

function over(e:Event):void {
 tocProduction.gotoAndPlay("over");
}
function over1(e:Event):void {
 tocWardrobe.gotoAndPlay("over");
}
function over2(e:Event):void {
 tocMakeup.gotoAndPlay("over");
}
function over3(e:Event):void {
 tocIllustrators.gotoAndPlay("over");
}
function over4(e:Event):void {
 tocSpecialfx.gotoAndPlay("over");
}
function over5(e:Event):void {
 tocAssisting.gotoAndPlay("over");
}
function over6(e:Event):void {
 tocContact.gotoAndPlay("over");
}

2 个答案:

答案 0 :(得分:3)

使用继承自(看起来像)MovieClip的基类,将构造函数设置为执行公共init并使用动态部分的变量(例如看起来像补间持续时间)。

您可以做的另一件事是合并事件监听器:

tocProduction.addEventListener(MouseEvent.MOUSE_OVER, overHandler);
tocWardrobe.addEventListener(MouseEvent.MOUSE_OVER, overHandler);
tocMakeup.addEventListener(MouseEvent.MOUSE_OVER, overHandler);
tocIllustrators.addEventListener(MouseEvent.MOUSE_OVER, overHandler);
tocSpecialfx.addEventListener(MouseEvent.MOUSE_OVER, overHandler);
tocAssisting.addEventListener(MouseEvent.MOUSE_OVER, overHandler);
tocContact.addEventListener(MouseEvent.MOUSE_OVER, overHandler);

function overHandler(event:Event):void {
 event.target.gotoAndPlay("over");
}

答案 1 :(得分:2)

不确定。将它们推入数组,然后执行以下操作:

for(var i in myArr) {
    var o = myArr[i];
    o.alpha=0;
    o.x = 400;
    TweenMax.to(o, 1, {alpha:1, easy:Circ.easeIn});
    o.addEventListener(MouseEvent.MOUSE_OVER, function(e:Event) {e.target.gotoAndPlay("over");});
}
相关问题