package
{
import flash.display.Bitmap;
import flash.display.Loader;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.filters.BlurFilter;
import flash.net.URLRequest;
public class Main extends Sprite
{
private var _pic:Loader;
private var _pic2:Loader;
private var _bit:Bitmap;
private var abc:Sprite;
private var bo:Boolean = false; //表示当前鼠标不进行绘图
public function Main():void
{
//载入图片
_pic = new Loader();
_pic2 = new Loader();
_pic.load(new URLRequest("pp.jpg"));
//监听加载完毕事件
_pic.contentLoaderInfo.addEventListener(Event.COMPLETE,loadok);
}
private function loadok(evt:Event):void
{
//----上层添加模糊图片的写法---------------------
//定义模糊滤镜
//var lvjing:BlurFilter = new BlurFilter();
//lvjing.blurX = 0;
//lvjing.blurY = 0;
//_pic.filters = [lvjing]; //模糊设置绑定到图片上
//将使用了模糊滤镜的图片添加到舞台
//this.addChild(_pic);
//将保持原有清晰度的图片添加到舞台(该图片在模糊图片的上层)
//_bit = new Bitmap(evt.target.loader.content.bitmapData);
//this.addChild(_bit);
//给清晰图片上加一层遮罩层(遮罩也就是把当前图片遮住,隐藏)
//abc = new Sprite();
//_bit.mask = abc;
//this.addChild(abc);
//----上层添加一张新图的写法----------------------------------------
//将下层的原图添加到舞台
this.addChild(_pic);
//载入另一张图片,并添加到舞台(放置在之前图片的上层)
_pic2 = new Loader();
_pic2.load(new URLRequest("pp2.jpg"));
this.addChild(_pic2);
//创建一个遮罩对象
abc = new Sprite();
//将遮罩应用在最上层的图片上,使之隐藏
_pic2.mask = abc;
this.addChild(abc);
//监听舞台中擦窗户的动作(鼠标事件)按住鼠标拖动时才是擦窗户
//鼠标按下
this.stage.addEventListener(MouseEvent.MOUSE_DOWN, down);
//鼠标移动
this.stage.addEventListener(MouseEvent.MOUSE_MOVE, mmove);
//鼠标抬起
this.stage.addEventListener(MouseEvent.MOUSE_UP, up);
}
//鼠标按下,设为可以绘图
private function down(evt:MouseEvent):void
{
bo = true;
}
//鼠标抬起,设为不可绘图
private function up(evt:MouseEvent):void
{
bo = false;
}
//鼠标移动,开始绘图
private function mmove(evt:MouseEvent):void
{
if(bo == true)
{
var a:Shape = new Shape();
a.graphics.beginFill(0x00ff00);
a.graphics.drawCircle(this.mouseX, this.mouseY, 25); //鼠标在哪,就在哪绘制
a.graphics.endFill();
//将绘制添加到遮罩层
abc.addChild(a);
}
}
}
}
{
import flash.display.Bitmap;
import flash.display.Loader;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.filters.BlurFilter;
import flash.net.URLRequest;
public class Main extends Sprite
{
private var _pic:Loader;
private var _pic2:Loader;
private var _bit:Bitmap;
private var abc:Sprite;
private var bo:Boolean = false; //表示当前鼠标不进行绘图
public function Main():void
{
//载入图片
_pic = new Loader();
_pic2 = new Loader();
_pic.load(new URLRequest("pp.jpg"));
//监听加载完毕事件
_pic.contentLoaderInfo.addEventListener(Event.COMPLETE,loadok);
}
private function loadok(evt:Event):void
{
//----上层添加模糊图片的写法---------------------
//定义模糊滤镜
//var lvjing:BlurFilter = new BlurFilter();
//lvjing.blurX = 0;
//lvjing.blurY = 0;
//_pic.filters = [lvjing]; //模糊设置绑定到图片上
//将使用了模糊滤镜的图片添加到舞台
//this.addChild(_pic);
//将保持原有清晰度的图片添加到舞台(该图片在模糊图片的上层)
//_bit = new Bitmap(evt.target.loader.content.bitmapData);
//this.addChild(_bit);
//给清晰图片上加一层遮罩层(遮罩也就是把当前图片遮住,隐藏)
//abc = new Sprite();
//_bit.mask = abc;
//this.addChild(abc);
//----上层添加一张新图的写法----------------------------------------
//将下层的原图添加到舞台
this.addChild(_pic);
//载入另一张图片,并添加到舞台(放置在之前图片的上层)
_pic2 = new Loader();
_pic2.load(new URLRequest("pp2.jpg"));
this.addChild(_pic2);
//创建一个遮罩对象
abc = new Sprite();
//将遮罩应用在最上层的图片上,使之隐藏
_pic2.mask = abc;
this.addChild(abc);
//监听舞台中擦窗户的动作(鼠标事件)按住鼠标拖动时才是擦窗户
//鼠标按下
this.stage.addEventListener(MouseEvent.MOUSE_DOWN, down);
//鼠标移动
this.stage.addEventListener(MouseEvent.MOUSE_MOVE, mmove);
//鼠标抬起
this.stage.addEventListener(MouseEvent.MOUSE_UP, up);
}
//鼠标按下,设为可以绘图
private function down(evt:MouseEvent):void
{
bo = true;
}
//鼠标抬起,设为不可绘图
private function up(evt:MouseEvent):void
{
bo = false;
}
//鼠标移动,开始绘图
private function mmove(evt:MouseEvent):void
{
if(bo == true)
{
var a:Shape = new Shape();
a.graphics.beginFill(0x00ff00);
a.graphics.drawCircle(this.mouseX, this.mouseY, 25); //鼠标在哪,就在哪绘制
a.graphics.endFill();
//将绘制添加到遮罩层
abc.addChild(a);
}
}
}
}