单击时,AS3会更改movieclip的颜色

时间:2015-01-19 13:24:47

标签: actionscript-3 flash

我有圈子动画片段作为按钮。单击某个圆MC时,它将以方形淡入淡出。我只是想知道如何使圆圈MC看起来像它被选中,就像点击时更改它的颜色一样?我有很多帧,所以我想gotoandstop thingy对我不起作用。

到目前为止

代码:

import flash.display.MovieClip; 
import flash.events.Event;  
import flash.events.MouseEvent;  

import fl.transitions.Tween;  
import fl.transitions.TweenEvent;  
import fl.transitions.easing.*;  

var fadeIn:Tween; 

var thisCircle:MovieClip; 
var thisSquare:MovieClip; 

var circles:Array = new Array(circle1,circle2,circle3,circle4); 
var squares:Array = new Array(square1,square2,square3,square4); 

for(var i:Number = 0; i < circles.length; i++) 
{ 
thisCircle = circles[i]; 
thisCircle.buttonMode = true; 
thisCircle.id = i; 
thisCircle.addEventListener(MouseEvent.CLICK, doFadeIn); 

thisSquare = squares[i]; 
thisSquare.alpha = 0; 
} 

function doFadeIn(e:MouseEvent):void  
{ 
e.currentTarget.mouseEnabled = false; 
trace(e.currentTarget.name + " is disabled while " + squares[e.currentTarget.id].name + " tweens in."); 
fadeIn = new Tween(squares[e.currentTarget.id],"alpha",None.easeNone,0,1,2.5,true);  
}

2 个答案:

答案 0 :(得分:1)

使用Color.setTint()。第一个参数是十六进制颜色;第二是阿尔法。将alpha设置为0以将其恢复为原始颜色。

var c:Color=new Color();
c.setTint(0xFF0000, 0.5);
myMC.transform.colorTransform = c;

答案 1 :(得分:1)

我还没有尝试过您的代码,但您可以尝试以下方式:

 // create a ColorTransform instance
 private var colorTransform:ColorTransform = new ColorTransform();     

 function doFadeIn(e:MouseEvent):void  
 { 
   e.currentTarget.mouseEnabled = false; 
   trace(e.currentTarget.name + " is disabled while " + squares[e.currentTarget.id].name + " tweens in."); 
   fadeIn = new Tween(squares[e.currentTarget.id],"alpha",None.easeNone,0,1,2.5,true);
   // defining some color
   colorTransform.color = 0xcc11cc;
   // apply the desired color to the respective MovieClip instance
   squares[e.currentTarget.id].transform.colorTransform = colorTransform;
 }