flex滑輪事件

<?xml version="1.0" encoding="utf-8"?>   
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml"    
                layout="absolute" width="500" height="500"    
                backgroundColor="#0A7276" toolTip="鼠標滑輪滾動可以控制圖片大小"  
                showCloseButton="true"  
                close="closeWindow()"  
                initialize="init()"  
                borderColor="#0A7276"  
                headerHeight="20"  
                title="{imgname}"  
                >   
    <mx:Script>   
        <![CDATA[   
            import mx.controls.Alert;   
            import mx.managers.PopUpManager;   
            private function closeWindow():void{   
                mx.managers.PopUpManager.removePopUp(this);   
            }   
            
            [Bindable]   
            private var source:String;   
            
            [Bindable]   
            private var imgname:String;   
            
            private function init():void{   
                this.width=this.screen.width-300;   
                this.height=this.screen.height-50;   
                this.x=(this.screen.width-this.width)/2;   
                this.y=(this.screen.height-this.height)/2;     
                addEventListernerToImage();   
            }   
            
            private function showSrcpage():void{   
                var u:URLRequest=new URLRequest(image.source.toString());   
                navigateToURL(u,'_blank');   
            }   
            
            private function addEventListernerToImage():void{   
                this.addEventListener(MouseEvent.MOUSE_WHEEL,mouseWheelHandler);   
            }   
            
            private function mouseWheelHandler(event:MouseEvent):void{   
                resizeImageSize(event.delta);//deta爲滑輪滾動時的刻度值   
            }   
            
            private function resizeImageSize(size:int):void{   
                var w:int;   
                var h:int;   
                if(size>0){   
                    w=image.width*(1+size/10);      
                    h=image.height*(1+size/10);   
                    
                }else if(size<0){   
                    w=image.width/(1-size/10)   
                    h=image.height/(1-size/10)   
                }   
                
                if(image.width<50||image.height<50){   
                    w=50;   
                    h=50*(image.height/image.width);   
                }else if(image.width>=this.width||image.height>=this.height){   
                    h=this.height-50;   
                    w=(h*image.width)/image.height;   
                }    
                image.width=w;   
                image.height=h;   
            }   
        ]]>   
    </mx:Script>         
    <mx:VBox height="100%" width="100%">   
        <mx:HBox height="100%" width="100%">   
            <mx:Spacer width="50%"/>   
            <mx:Image width="100%" height="100%"    
                      maxHeight="{this.height-40}" maxWidth="{this.width-50}"  
                      source="img/58.jpg" id="image"  
                      click="showSrcpage()"  mouseChildren="false"    
                      buttonMode="true" useHandCursor="true"  
                      />   
            <mx:Spacer width="50%"/>   
        </mx:HBox>             
    </mx:VBox>     
</mx:TitleWindow>   





 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章