Flex 图片缩放、托拽效果 Zoom版

<? xml version="1.0" encoding="utf-8" ?>
< mx:Application  xmlns:mx ="http://www.adobe.com/2006/mxml"   
    layout
="absolute"      width ="1014"  height ="590"  applicationComplete ="app(event)"  horizontalScrollPolicy ="off"  verticalScrollPolicy ="off"  verticalAlign ="middle"  horizontalAlign ="center" >
    
< mx:Script >
        
<![CDATA[
            import mx.events.EffectEvent;
            import mx.controls.Alert;
            import mx.events.FlexEvent;
            protected function app(event:FlexEvent):void
            {
            img.addEventListener(MouseEvent.MOUSE_DOWN, imgMouseDown);
            img.addEventListener(MouseEvent.MOUSE_UP, imgMouseUp);
            this.addEventListener(MouseEvent.MOUSE_WHEEL, imgZoom);
            }
            private function imgMouseDown(evt:MouseEvent):void
            {
                evt.currentTarget.startDrag();
            }
            private function imgMouseUp(evt:MouseEvent):void
            {
                evt.currentTarget.stopDrag();
            }
            private function imgZoom(evt:MouseEvent):void
            {
                var w:Number = evt.delta;
                var z:Number = fd.zoomHeightTo;
                if(w > 0 && z < 3)
                {
                    fd.stop();
                    fd.zoomHeightTo +=0.1;
                    fd.zoomWidthTo +=0.1;
                    fd.play();
                }
                if(w < 0 && z > 0.2)
                {
                    fd.stop();
                    fd.zoomHeightTo -=0.1;
                    fd.zoomWidthTo -=0.1;
                    fd.play();
                }

            }
            
        
]]>
    
</ mx:Script >
    
< mx:Image  y ="123"  id ="img"  source ="1.jpg"  x ="257" />
    
< mx:Zoom  id ="fd"  target ="{img}"   zoomHeightTo ="1"   zoomWidthTo ="1"  duration ="600" />   

</ mx:Application >

你可能感兴趣的:(Flex)