原图效果
过渡效果
这个效果可以用帧动画实现较为简单,只需要调节这个影片剪辑的色彩效果样式里面的高级选项的三个通道值,以下用代码简单测试,可作为文档类:
package
{
import com.tweener.transitions.Tweener;
import flash.display.Loader;
import flash.display.SimpleButton;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.ColorTransform;
import flash.net.URLRequest;
/**
* ...
* @author FrostYen
*/ public class ColorTransformExample extends Sprite
{
private var ldr:Loader = new Loader();
private var sp:Sprite = new Sprite();
private var btn:Sprite = new Sprite();
private var colorTransform:ColorTransform = new ColorTransform(1, 1, 1, 1, 255, 255, 255, 0);
private var frame:int=15;//相当于影片剪辑动画的帧数
public function ColorTransformExample() {
ldr.load(new URLRequest("image/farewell-to-fall.jpg"));
sp.transform.colorTransform = colorTransform;
btn.graphics.beginFill(0x666666);
btn.graphics.drawRect(0, 0, 100, 50);
btn.graphics.endFill();
btn.buttonMode = true;
btn.x = 700;
btn.y = 100;
this.addChild(btn);
this.addChild(sp);
sp.addChild(ldr);
stage.frameRate = 36;//帧频 ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);
btn.addEventListener(MouseEvent.CLICK, onClick);
} private function onClick(e:MouseEvent):void
{
addEventListener(Event.ENTER_FRAME, onEnter);
} private function onEnter(e:Event):void
{
if (colorTransform.redOffset > 0) {
colorTransform.redOffset -= 255/frame;
colorTransform.greenOffset -= 255/frame;
colorTransform.blueOffset -= 255/frame;
sp.transform.colorTransform = colorTransform;
}else {
colorTransform = new ColorTransform(1, 1, 1, 1, 255, 255, 255, 0);
removeEventListener(Event.ENTER_FRAME, onEnter);
}
} private function onImageLoaded(e:Event):void
{ }
}
}