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

as 3.0做放大镜效果代码

参数变量:mc:需要放大的图形*/ as 3.0做放大镜效果代码
package maths{
        import flash.display.Bitmap;
        import flash.display.BitmapData;
        import flash.display.Sprite;
        import flash.geom.Rectangle;
        import flash.geom.Matrix;
        import flash.events.MouseEvent;
        import flash.geom.Point;
        public class ZoomImage extends Sprite {
                private var sprBitmapData:BitmapData;
                private var sprBitmap:Bitmap;
                private var Rect:Rectangle;
                private var Matr:Matrix;
                private var mc:Sprite;
                private var Mdown_x,Mdown_y,Mup_x,Mup_y:Number;
                public function ZoomImage(_mc:Sprite) {
                        mc=_mc;
                        mc.addEventListener(flash.events.MouseEvent.MOUSE_DOWN,Mdown_fc);
                        mc.addEventListener(flash.events.MouseEvent.MOUSE_MOVE,Mmove_fc);
                        mc.addEventListener(flash.events.MouseEvent.MOUSE_UP,Mup_fc);

                }//end of ZoomImage
                private function Mdown_fc(e:flash.events.MouseEvent) {
                        Mdown_x=e.localX;
                        Mdown_y=e.localY;
                }//end of Mdown_fc
                private function Mmove_fc(e:flash.events.MouseEvent) {
                }//end of Mmove_fc
                private function Mup_fc(e:flash.events.MouseEvent) {
                        if (e.localX > Mdown_x && e.localY > Mdown_y) {
                                var localPoint=new Point(Mdown_x,Mdown_y);
                                if (sprBitmap != null) {
                                        removeChild(sprBitmap);
                                }
                                Mup_x=e.localX;
                                Mup_y=e.localY;
                                Matr=new Matrix(1,0,0,1,- Mdown_x,- Mdown_y);
                                sprBitmapData=new BitmapData(Mup_x - Mdown_x,Mup_y - Mdown_y);
                                sprBitmap=new Bitmap(sprBitmapData);
                                sprBitmapData.draw(mc,Matr);
                                addChild(sprBitmap);
                                this.scaleX=this.scaleY=2;
                                this.x=mc.localToGlobal(localP).x;
                                this.y=mc.localToGlobal(localP).y;
                                //
                                this.addEventListener(flash.events.MouseEvent.MOUSE_DOWN,MD_fc);
                                this.addEventListener(flash.events.MouseEvent.MOUSE_UP,MU_fc);
                                this.addEventListener(flash.events.MouseEvent.MOUSE_WHEEL,MW_fc);
                        }
                }//end of Mup_fc
                private function MW_fc(e:flash.events.MouseEvent) {
                        if (e.target.scaleX>1&&e.target.scaleX<5) {
                                e.target.scaleX+=0.03*e.delta;
                                e.target.scaleY+=0.03*e.delta;
                        }else{
                                e.target.scaleX=e.target.scaleY=1.1;
                                }
                }//end of MW_fc
                private function MD_fc(e:flash.events.MouseEvent) {
                        e.target.startDrag(); 
                }//end of MD_fc
                private function MU_fc(e:flash.events.MouseEvent) {
                        e.target.stopDrag();
                }//end of MU_fc
        }//end of class
}//end of package

效果图.

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