有点像“水果忍者”划过屏幕时的动画,在每次按住鼠标左键不放然后拖动鼠标并释放,会出现动画。动画我参考别人的代码,然后在显示特效的时候使用了不同的颜色。

package
   2: {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.filters.GlowFilter;
/**
     * ...
     * @author Meteoric_cry
     */
extends Sprite
  12:     {
private var _scene:Sprite;
  14:         
int;
int;
  17:         
private var _isDown:Boolean;
  19:         
int = 20;
  21:         
public function MouseEffectDemo() 
  23:         {
  24:             initView();
  25:         }
  26:         
void
  28:         {
new Sprite();
  30:             
  31:             addChild(_scene);
  32:             
  33:             _scene.filters = [getGlowFilter(0x00CCFF)];
  34:             
  35:             stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDownHandler);
  36:             stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUpHandler);
  37:         }
  38:         
void
  40:         {
  41:             unlistenerEnterFrameHandler();
  42:             
  43:             stage.addEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
  44:         }
  45:         
void
  47:         {
  48:             stage.removeEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
  49:         }
  50:         
void 
  52:         {
//LineArr的长度可能会动态变化,详情参见它的update方法
for each (var line:Line in Line.lineArr)
  55:             {
  56:                 line.update();
  57:             }
  58:             
  59:             update();            
  60:         }
  61:         
void
  63:         {
if (_isDown == false)
  65:             {
if (Line.lineArr.length === 0)
  67:                 {
  68:                     unlistenerEnterFrameHandler();
  69:                 }
  70:                 
return ;
  72:             }
  73:             
int = mouseX;
int = mouseY;
  76:             
if (Math.abs(_startX - endX) < MIN_POINT_DISTANCE || Math.abs(_startY - endY) < MIN_POINT_DISTANCE)
  78:             {
return ;
  80:             }
  81:             
new Line(_startX, _startY, endX, endY);
  83:             
  84:             _scene.addChild(line);
  85:             
  86:             _startX = endX;
  87:             _startY = endY;            
  88:         }
  89:         
void 
  91:         {
  92:             _isDown = false;
  93:         }
  94:         
void 
  96:         {
  97:             _isDown = true;
  98:             
  99:             changeColorHandler();
 100:             
 101:             _startX = mouseX;
 102:             _startY = mouseY;
 103:             
 104:             listenerEnterFrameHandler();
 105:         }
 106:         
private function getGlowFilter(color:Number):GlowFilter
 108:         {
new GlowFilter(color, 1, 10, 10, 2, 1, false, false)
 110:         }
 111:         
void
 113:         {
 114:             var colorArr:Array = [0x00CCFF, 0xF5001D, 0xBC0093, 0x00CE00, 0xFF7400];
 115:             var color:Number = colorArr[Math.floor(Math.random() * colorArr.length)];
 116:             
 117:             _scene.filters = [getGlowFilter(color)];
 118:         }
 119:         
 120:     }
 121:  
 122: }

相关文章: