Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package {
- import flash.display.*;
- import flash.events.*;
- import flash.geom.Rectangle;
- import flash.geom.Matrix;
- public class DelayedMask extends MovieClip {
- var maskDisplay:Bitmap;
- var maskRenderers:Vector.<BitmapData>;
- var maskRenderIndex:uint;
- const maskRenderCount:uint=2;
- public var guy_mc:DisplayObject;
- public var content_mc:DisplayObject;
- public function DelayedMask() {
- maskRenderers=new Vector.<BitmapData>();
- for(var i:uint=0;i<maskRenderCount;++i) {
- var maskRenderer:BitmapData=new BitmapData(guy_mc.width,guy_mc.height,true);
- maskRenderers[i]=maskRenderer;
- }
- maskDisplay=new Bitmap();
- addChild(maskDisplay);
- //guy_mc.visible=false;
- maskDisplay.mask=guy_mc;
- stage.addEventListener(MouseEvent.MOUSE_MOVE,mMove);
- addEventListener(Event.EXIT_FRAME,updateMask);
- }
- private function mMove(e:MouseEvent):void {
- guy_mc.x=mouseX;
- guy_mc.y=mouseY;
- }
- private function updateMask(e:Event):void {
- var maskRenderer:BitmapData=maskRenderers[maskRenderIndex];
- maskRenderer.lock();
- maskRenderer.fillRect(new Rectangle(0,0,guy_mc.width,guy_mc.height),0x00FF00FF);
- var transform:Matrix=content_mc.transform.matrix;
- var transform2:Matrix=guy_mc.transform.matrix;
- transform2.invert();
- transform.concat(transform2);
- maskRenderer.draw(content_mc,transform);
- maskRenderer.unlock();
- maskRenderIndex=(maskRenderIndex+1)%maskRenderCount;
- maskDisplay.bitmapData=maskRenderers[maskRenderIndex];
- maskDisplay.x=guy_mc.x;
- maskDisplay.y=guy_mc.y;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement