flash on 2010-6-22
package {
import flash.display.Sprite;
import flash.display.GradientType;
import flash.geom.ColorTransform;
import flash.events.MouseEvent;
import flash.events.Event;
public class ColorTransformExample extends Sprite {
public var speed:int = 2;
public function ColorTransformExample() {
var target:Sprite = new Sprite();
draw(target);
addChild(target);
target.useHandCursor = true;
target.buttonMode = true;
target.addEventListener(MouseEvent.CLICK, clickHandler)
target.addEventListener(Event.ENTER_FRAME, loop);
}
public function draw(sprite:Sprite):void {
var red:uint = 0xFF0000;
var green:uint = 0x00FF00;
var blue:uint = 0x0000FF;
var size:Number = 100;
sprite.graphics.beginGradientFill(GradientType.LINEAR, [red, blue, green], [1, 0.5, 1], [0, 200, 255]);
sprite.graphics.drawRect(0, 0, 100, 100);
}
public function clickHandler(event:MouseEvent):void {
var rOffset:Number = transform.colorTransform.redOffset + 25;
var bOffset:Number = transform.colorTransform.redOffset - 25;
this.transform.colorTransform = new ColorTransform(1, 1, 1, 1, rOffset, 0, bOffset, 0);
}
public function loop(event:Event):void{
this.rotationX+=1*speed;
this.rotationY+=1;
this.rotationZ+=1;
this.x +=1
this.y +=1*0.99+speed/100;
speed++
}
}
}