2012、10、05 听课笔记
擦窗户制作
package{
import flash.display.Sprite;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.filters.BlurFilter;
import flash.display.Bitmap;
import flash.events.MouseEvent;
import flash.display.Shape;
public class Main extends Sprite
{
private var _pic:Loader;
private var bit:Bitmap;
private var zhezhao:Sprite;
private var bo:Boolean = false;
public function Main():void
{
init();
}
private function init():void
{
_pic = new Loader();
_pic.contentLoaderInfo.addEventListener(Event.COMPLETE,loadok);
_pic.load(new URLRequest('a.jpg'));
}
private function loadok(evt:Event):void
{
addChild(_pic);
bit = new Bitmap(evt.target.loader.content.bitmapData);
////模糊滤镜
var lvjing:BlurFilter = new BlurFilter();
lvjing.blurX = 10;
lvjing.blurY = 10;
_pic.filters = [lvjing];
////
addChild(bit);
////
zhezhao = new Sprite();
bit.mask = zhezhao;
addChild(zhezhao);
////
stage.addEventListener(MouseEvent.MOUSE_DOWN,down);
stage.addEventListener(MouseEvent.MOUSE_MOVE,mmove);
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)
{
var a:Shape = new Shape();
a.graphics.beginFill(0x00ff00);
a.graphics.drawCircle(mouseX,mouseY,20);
a.graphics.endFill();
zhezhao.addChild(a);
}
}
}
}
放大镜的制作
package{
import flash.display.Sprite;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.MouseEvent;
public class Main extends Sprite
{
private var picbitmap:BitmapData
private var mybitmap:Bitmap
public function Main():void
{
init();
}
private function init():void
{
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loadok);
var url:URLRequest = new URLRequest('a.jpg');
loader.load(url);
}
private function loadok(evt:Event):void
{
picbitmap = evt.target.content.bitmapData;
var a:Bitmap = new Bitmap(picbitmap);
a.width=400;
a.height=300;
addChild(a);
/////////////
var tu:Sprite= new Sprite();
tu.graphics.beginFill(0x000000);
tu.graphics.drawCircle(0,0,60);
tu.graphics.endFill();
tu.startDrag(true);
addChild(tu);
////////////////
mybitmap = new Bitmap(picbitmap);
mybitmap.mask = tu;
addChild(mybitmap);
///////////////////
stage.addEventListener(MouseEvent.MOUSE_MOVE,onmove);
}
private function onmove(evt:MouseEvent):void
{
mybitmap.x = (mybitmap.width-400)*(stage.mouseX/400)*-1
mybitmap.y = (mybitmap.height-300)*(stage.mouseY/300)*-1
}
}
}