package{
import flash.display.Sprite;
import flash.geom.ColorTransform;
import flash.events.MouseEvent;
import flash.utils.setInterval;
import flash.utils.clearInterval;
public class Example extends Sprite
{
private var _container: Sprite;
private var _circle0: Sprite;
private var _circle1: Sprite;
private var _circle2: Sprite;
private var colorA: ColorTransform; //현재색
private var colorB: ColorTransform; //변할색
private var colorArray: Array; //8가지 ColorTransform요소
private var spriteColor: Array; //기본색배열
private var changeCArray: Array; //변해야하는색배열
private var setId: uint; //setInterval사용 변수
private var updown_array: Array;
private var speed_array: Array;
private var slowNumber: int;
public function Example()
{
_container=new Sprite();
addChild( _container );
spriteColor=new Array( 0x000000,0x5F5F5F,0xE4E4E4 );
changeCArray=new Array( 0xFF0000,0x00FF00,0x0000FF );
slowNumber=100;
colorArray=new Array( "redMultiplier","greenMultiplier","blueMultiplier","alphaMultiplier",
"redOffset","greenOffset","blueOffset","alphaOffset" );
colorA=new ColorTransform();
colorB=new ColorTransform();
for(var i:int=0; i<3; i++){
this["_circle"+i]=creatCircle( spriteColor[i], 50,100+150*i, 100 ,i );
_container.addChild(this["_circle"+i]);
this["_circle"+i].addEventListener( MouseEvent.MOUSE_OVER, onMouseOverEffect );
this["_circle"+i].addEventListener( MouseEvent.MOUSE_OUT, onMouseOutEffect );
}
}
private function creatCircle
(spColor:Number,cLength:Number,xpos:Number,ypos:Number,nameNum:Number): Sprite{
var sampSprite: Sprite;
sampSprite=new Sprite();
sampSprite.graphics.beginFill( spColor );
sampSprite.graphics.drawCircle( 0,0,cLength );
sampSprite.graphics.endFill();
sampSprite.x=xpos;
sampSprite.y=ypos;
sampSprite.name=String( nameNum );
return sampSprite;
}
private function onMouseOutEffect( event:MouseEvent ): void{
var mcNumber:int=Number( event.target.name );
colorB.color=spriteColor[mcNumber];
myEffect( event.target );
trace( event.target.name );
}
private function onMouseOverEffect( event:MouseEvent ): void{
clearInterval( setId );
var mcNumber: int=Number( event.target.name );
colorA.color=spriteColor[mcNumber];
colorB.color=changeCArray[mcNumber];
myEffect( event.target );
trace( event.target.name );
}
private function myEffect(valueName:Object): void{
clearInterval( setId ); //왜 여기서 한번 더 사용한 것인지 체크 필요
//for( var j:int=0; j<3; j++ ){
//this["_circle"+j].transform.colorTransform=new ColorTransform();
// }
updown_array= new Array();
speed_array = new Array();
for(var i:Number=0; i<8; i++){
if(colorA[colorArray[i]] > colorB[colorArray[i]]){
updown_array.push("u");
}else if(colorA[colorArray[i]] < colorB[colorArray[i]]){
updown_array.push("d");
}else{
updown_array.push("same");
}
var speed_0 : Number = Math.abs(colorA[colorArray[i]] - colorB[colorArray[i]]);
var speed_1: Number = speed_0 /slowNumber;
speed_array.push(speed_1);
}
setId=setInterval( changeColor,0,valueName );
}
////
private function changeColor( valueName:Object ): void{
for(var i:Number=0; i<8; i++){
if(updown_array[i] == "u"){
if(colorA[colorArray[i]] > colorB[colorArray[i]]){
colorA[colorArray[i]] = colorA[colorArray[i]] - speed_array[i];
}else{
colorA[colorArray[i]] = colorB[colorArray[i]];
}
}else if(updown_array[i] == "d"){
if(colorA[colorArray[i]] < colorB[colorArray[i]]){
colorA[colorArray[i]] = colorA[colorArray[i]] + speed_array[i];
}else{
colorA[colorArray[i]] = colorB[colorArray[i]];
}
}else{
colorA[colorArray[i]] = colorB[colorArray[i]];
}
}
if(colorA.color == colorB.color){
clearInterval( setId );
}else{
valueName.transform.colorTransform = colorA;
}
}///
}
}
[출처] as3 ColorTransform|작성자 탈훼인
'코드 > ActionScript & MXML' 카테고리의 다른 글
스케일폼 4.0에서 AS3.0 지원 (0) | 2011.04.02 |
---|---|
NetStream 클래스에서 NetStatusEvent, onMetaData (0) | 2011.02.16 |
렌더링 문답. (0) | 2010.10.31 |
FITC 2010 gskinner Quick Flash 플래시 컨텐츠 최적화 (0) | 2010.10.02 |
AS3.0 리스너 자동 제거하기. (0) | 2010.10.02 |