Flex 图片缩放、托拽效果

 


< mx:Application  xmlns:mx ="http://www.adobe.com/2006/mxml"   
    layout
="absolute"      width ="800"  height ="500"  applicationComplete ="app(event)"  horizontalScrollPolicy ="off"  verticalScrollPolicy ="off" >
    
< mx:Script >
        
<![CDATA[
            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 = img.width * evt.delta * 0.02;
                var h:Number = img.height * evt.delta * 0.02;
                img.x += -w/2;
                img.y += -h/2;
                
                img.width += w;
                img.height += h;
                //Alert.show(img.width.toString());
            }
        
]]>
    
</ mx:Script >
    
< mx:Image  x ="70"  y ="85"  id ="img"  source ="1.jpg" />
</ mx:Application >

 

 

 

你可能感兴趣的:(Flex)