开发者

How can I change this code into an array?

开发者 https://www.devze.com 2022-12-16 18:52 出处:网络
Any suggestions would be appreciated tocProduction.alpha = 0; tocWardrobe.alpha = 0; tocMakeup.alpha = 0;

Any suggestions would be appreciated

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;
t开发者_如何学JAVAocMakeup.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");
}


Use a base class that inherits from (what looks like) a MovieClip, set the constructor to do the common init and use variables for the dynamic parts (such as what looks like the tween duration).

Another thing you can do is merge the event listeners:

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");
}


Sure. Push them into an array, and then do something like:

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");});
}
0

精彩评论

暂无评论...
验证码 换一张
取 消