当前位置:软件学习 > Flash >>

flash as3 遮罩层效果

 代码如下 复制代码

package
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.BitmapDataChannel;
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.filters.BlurFilter;
    import flash.geom.Point;
    import flash.geom.Rectangle;
 
    /**
     * ...
     * @author lizhi
     */
    public class Main extends Sprite
    {
        private var image:Bitmap;
        private var sb:BitmapData;
        private var bmd:BitmapData;
        private var bmdclone:BitmapData;
 
        public function Main():void
        {
            [Embed(source = "460.jpg")]var c:Class;
            bmd = (new c as Bitmap).bitmapData;
 
            image = new Bitmap();
            addChild(image);
            var s:Shape = new Shape;
            s.graphics.beginFill(0);
            s.graphics.drawCircle(50, 50, 30);
            s.filters=[new BlurFilter(15,15,3)]
            sb = new BitmapData(100, 100, true, 0);
            sb.draw(s);
 
            stage.addEventListener(MouseEvent.MOUSE_MOVE, stage_mouseMove);
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
        }
 
        private function stage_mouseMove(e:MouseEvent):void
        {
 
            bmdclone = new BitmapData(bmd.width, bmd.height, true, 0);
            bmdclone.setVector(new Rectangle(mouseX - 50,mouseY - 50,100,100), bmd.getVector(new Rectangle(mouseX - 50,mouseY - 50,100,100)));
            bmdclone.copyChannel(sb, sb.rect, new Point(mouseX - 50, mouseY - 50), BitmapDataChannel.ALPHA, BitmapDataChannel.ALPHA);
            image.bitmapData = bmdclone;
            e.updateAfterEvent();
 
        }
 
    }
 
}

效果地址 http://game-develop.net/swfs/meinvfilter/

其实原理很简单就是一个flash 随便走兆层的效果了。

 

补充:flash教程,As3.0
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,