개발/FLEX & AIR

Flex 컴포넌트의 비율 유지

내가지니 2009. 12. 21. 15:33

<?xml version="1.0" encoding="utf-8"?>
<mx:Application verticalAlign="middle" horizontalAlign="center"
   paddingBottom="0" paddingLeft="0" paddingRight="0" paddingTop="0"
   xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
   <mx:Script>
         <![CDATA[
            private const ratio:Number = .75;
            override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
                   super.updateDisplayList(unscaledWidth,unscaledHeight);
                   btn.width = unscaledWidth;
                   btn.height = unscaledHeight;
                   var tmpRatio:Number = btn.height / btn.width;
                   if(tmpRatio>ratio){
                         btn.height = btn.width * ratio;
                   }else{
                         btn.width = btn.height / ratio;                                                       
                   }                         
            }
         ]]>
   </mx:Script>
   <mx:Button id="btn" width="50%" height="50%"/>
</mx:Application>