ActionScript 3 绘画Flash CS3:实时擦除工具

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 绘画Flash CS3:实时擦除工具相关的知识,希望对你有一定的参考价值。

import flash.events.MouseEvent;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.display.GradientType;
//
import flash.geom.Matrix;
//
var md:Boolean = false;
//
var event_spr:Sprite = new Sprite();
addChild (event_spr);
//
var area_width:Number = event_spr.stage.stageWidth;
var area_height:Number = event_spr.stage.stageHeight-32;
//
var fillType:String = GradientType.LINEAR;
var colors:Array = [0xFF0000, 0x00FF00, 0x0000ff];
var alphas:Array = [1, 1, 1];
var ratios:Array = [0, 128, 255];
var spreadMethod:String = SpreadMethod.PAD;
var matrix:Matrix = new Matrix();
matrix.createGradientBox (area_width, area_height, 1, 0, 0);
//
with (event_spr.graphics) {
	beginGradientFill (fillType,colors,alphas,ratios,matrix,spreadMethod);
	drawRect (0,0,area_width, area_height);
	endFill ();
}
// paint event
event_spr.addEventListener (MouseEvent.MOUSE_DOWN, _onMouseDown);
event_spr.addEventListener (MouseEvent.MOUSE_MOVE, _onMouseMove);
event_spr.addEventListener (MouseEvent.MOUSE_UP, _onMouseUp);
event_spr.addEventListener (MouseEvent.MOUSE_OUT, _onMouseUp);
//
var bmpd:BitmapData = new BitmapData(event_spr.width,event_spr.height,true,0);
var bmp:Bitmap = new Bitmap(bmpd);
addChild (bmp);
//
// shape temporanea
var draw_shape:Shape = new Shape();
addChild (draw_shape);
//
// shape, non visibile, usata per la "cancellazione"
var erase_shape:Shape = new Shape();
//
function _onMouseDown (e:MouseEvent):void {
	debug ("_onMouseDown");
	draw_shape.graphics.lineStyle (10, 0xffffff, 1);
	erase_shape.graphics.lineStyle (20, 0xffffff, 1);
	draw_shape.graphics.moveTo (e.localX,e.localY);
	erase_shape.graphics.moveTo (e.localX,e.localY);
	md = true;
}
//
function _onMouseUp (e:MouseEvent):void {
	md = false;
	bmp.bitmapData.draw (draw_shape);
	draw_shape.graphics.clear ();
	erase_shape.graphics.clear ();
}
//
function _onMouseMove (e:MouseEvent):void {
	debug ("_onMouseMove");
	if (md && !e.ctrlKey) {
		draw_shape.graphics.lineTo (e.localX,e.localY);
	} else if (md && e.ctrlKey) {
		erase_shape.graphics.lineTo (e.localX,e.localY);
		bmp.bitmapData.draw (erase_shape,null,null,"erase");
	}
}
//
function debug (v:String):void {
	var d:Date = new Date();
	trace (d.getMinutes()+":"+d.getSeconds()+":"+d.getMilliseconds()+": "+v);
}

以上是关于ActionScript 3 绘画Flash CS3:实时擦除工具的主要内容,如果未能解决你的问题,请参考以下文章

ActionScript 3 Flash CS3:模板per la classe Documento

ActionScript 3 Flash CS3:comunicazione con un Web Server

Flash cs6 - Actionscript 3:使用输入 txt 更改动态 txt

使用带有actionscript 3 Flash cs6的矩形或线条创建2D重复模式

如何创建由 xml 文件驱动的 Adob​​e Flash cs6 Actionscript 3 rtmp 视频播放器?

在 Adob​​e Flash CS3 Actionscript 中拖动多个项目