[ActionScript 3.0] 利用ColorTransform实现对象(图片)的曝光过渡效果

[ActionScript 3.0] 利用ColorTransform实现对象(图片)的曝光过渡效果

原图效果

[ActionScript 3.0] 利用ColorTransform实现对象(图片)的曝光过渡效果

过渡效果

这个效果可以用帧动画实现较为简单,只需要调节这个影片剪辑的色彩效果样式里面的高级选项的三个通道值,以下用代码简单测试,可作为文档类:

 1 package

 2 {

 3     import com.tweener.transitions.Tweener;

 4     import flash.display.Loader;

 5     import flash.display.SimpleButton;

 6     import flash.display.Sprite;

 7     import flash.events.Event;

 8     import flash.events.MouseEvent;

 9     import flash.geom.ColorTransform;

10     import flash.net.URLRequest;

11     /**

12      * ...

13      * @author FrostYen

14      */

15  

16     public class ColorTransformExample extends Sprite

17     {

18         private var ldr:Loader = new Loader();

19         private var sp:Sprite = new Sprite();

20         private var btn:Sprite = new Sprite();

21         private var colorTransform:ColorTransform = new ColorTransform(1, 1, 1, 1, 255, 255, 255, 0);

22         private var frame:int=15;//相当于影片剪辑动画的帧数

23         public function ColorTransformExample() {

24             ldr.load(new URLRequest("image/farewell-to-fall.jpg"));

25             sp.transform.colorTransform = colorTransform;

26             btn.graphics.beginFill(0x666666);

27             btn.graphics.drawRect(0, 0, 100, 50);

28             btn.graphics.endFill();

29             btn.buttonMode = true;

30             btn.x = 700;

31             btn.y = 100;

32             this.addChild(btn);

33             this.addChild(sp);

34             sp.addChild(ldr);

35             stage.frameRate = 36;//帧频

36    

37             ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);

38             btn.addEventListener(MouseEvent.CLICK, onClick);

39         }

40   

41         private function onClick(e:MouseEvent):void

42         {

43             addEventListener(Event.ENTER_FRAME, onEnter);

44         }

45   

46         private function onEnter(e:Event):void

47         {

48             if (colorTransform.redOffset > 0) {

49                 colorTransform.redOffset -= 255/frame;

50                 colorTransform.greenOffset -= 255/frame;

51                 colorTransform.blueOffset -= 255/frame;

52                 sp.transform.colorTransform = colorTransform;

53             }else {

54                 colorTransform = new ColorTransform(1, 1, 1, 1, 255, 255, 255, 0);

55                 removeEventListener(Event.ENTER_FRAME, onEnter);

56             }

57         }

58   

59         private function onImageLoaded(e:Event):void

60         {

61    

62         }

63     }

64 }

 

你可能感兴趣的:(actionscript)