MarkTu
MarkTu

Reputation: 39

AS3 change color of movieclip when clicked

I have circle movieclips which act as buttons. When a certain circle MC is clicked, it will fade in a square. I just want to know how to make the circle MC appear like it's selected, like changing it's color when clicked maybe? I have a lot of frames so I guess the gotoandstop thingy won't work for me.

Code so far:

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

Upvotes: 0

Views: 3936

Answers (2)

gabriel
gabriel

Reputation: 2359

I haven't tried your code, but you can try something like:

 // 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;
 }

Upvotes: 1

Atriace
Atriace

Reputation: 2558

Use Color.setTint(). First argument is the hex color; second is the alpha. Set the alpha to 0 to return it to its original color.

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

Upvotes: 2

Related Questions