2010-01-19 43 views
0

任何建议,将不胜感激如何将此代码更改为数组?

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

不是所有alpha值设置为0,你可以使用TweenMax.from。 – 2010-01-19 22:16:34

回答

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

这是更好的方法。 – 2010-01-19 22:09:55

相关问题