一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

flash as3 遮罩层效果

时间:2022-06-28 22:16:46 编辑:袖梨 来源:一聚教程网

 代码如下 复制代码

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 随便走兆层的效果了。

 

热门栏目