Alpha mask (as3)
[ 2009-06-21 10:23:07 | Author: liuhuan ]
Alpha mask is always not easy in flash, though it's so simple in other adobe produts like after effect. We can not simply make alpha mask with timeline orders. By the mergeAlpha parameter in copyPixels method, we can easily make alpha mask in actionscript 3.
source file:
Click Here To Download
var maskerbmp:BitmapData = new BitmapData(masker.width, masker.height, true, 0);
var picbmp:BitmapData = new BitmapData(pic.width, pic.height, true, 0);
maskerbmp.draw(masker);
picbmp.draw(pic);
var shownbmp:BitmapData = new BitmapData(pic.width, pic.height, true, 0);
var bmp:Bitmap = new Bitmap(shownbmp);
this.addChild(bmp);
this.addEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
function onEnterFrameHandler(e:Event) {
var rect1:Rectangle = new Rectangle(0, 0, masker.width, masker.height);
var rect2:Rectangle = new Rectangle(0, 0, pic.width, pic.height);
shownbmp.fillRect(rect2, 0);
rect1.x = mouseX - masker.width/2;
rect1.y = mouseY - masker.height/2;
var pt1:Point = new Point(mouseX - masker.width/2, mouseY - masker.height/2);
var pt2:Point = new Point(0, 0);
shownbmp.copyPixels(picbmp, rect1, pt1,maskerbmp, pt2, true);
}
var picbmp:BitmapData = new BitmapData(pic.width, pic.height, true, 0);
maskerbmp.draw(masker);
picbmp.draw(pic);
var shownbmp:BitmapData = new BitmapData(pic.width, pic.height, true, 0);
var bmp:Bitmap = new Bitmap(shownbmp);
this.addChild(bmp);
this.addEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
function onEnterFrameHandler(e:Event) {
var rect1:Rectangle = new Rectangle(0, 0, masker.width, masker.height);
var rect2:Rectangle = new Rectangle(0, 0, pic.width, pic.height);
shownbmp.fillRect(rect2, 0);
rect1.x = mouseX - masker.width/2;
rect1.y = mouseY - masker.height/2;
var pt1:Point = new Point(mouseX - masker.width/2, mouseY - masker.height/2);
var pt2:Point = new Point(0, 0);
shownbmp.copyPixels(picbmp, rect1, pt1,maskerbmp, pt2, true);
}
source file:
Click Here To Download
Comments Feed: http://www.liuhuan.com/blog/feed.asp?q=comment&id=990
There is no comment on this article.
You can't post comment on this article.