2010-01-19 54 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