Flex/AIR/AS3/Component2009.08.31 17:01

Tree의 내용이 변경되어 스크롤바의 크기가 제대로 적용되지 않을 경우 Tree를 확장하여 크기에 따라 스크롤을 재정의 한다.

Tree크기에 따른 스크롤바 크기 자동설정

    import flash.events.Event; 
    import mx.controls.Tree; 
    import mx.core.mx_internal; 
    import mx.core.ScrollPolicy; 
    import mx.events.TreeEvent; 

    public class AutoSizeTree extends Tree { 
          public function AutoSizeTree(){ 
              horizontalScrollPolicy = ScrollPolicy.AUTO; 
          // we need to override maxHorizontalScrollPosition because setting 
          // Tree's maxHorizontalScrollPosition adds an indent value to it, 
          // which we don't need as measureWidthOfItems seems to return exactly 
          // what we need.  Not only that, but getIndent() seems to be broken 
          // anyways (SDK-12578). 
          // I hate using mx_internal stuff, but we can't do 
          // super.super.maxHorizontalScrollPosition in AS 3, so we have to 
          // emulate it. 

          override public function get maxHorizontalScrollPosition():Number          { 
              return mx_internal::_maxHorizontalScrollPosition; 
          override public function set maxHorizontalScrollPosition(value:Number):void { 
              mx_internal::_maxHorizontalScrollPosition = value; 
              dispatchEvent(new Event("maxHorizontalScrollPositionChanged")); 
              scrollAreaChanged = true; 
          override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void 
              // we call measureWidthOfItems to get the max width of the item renderers. 
              // then we see how much space we need to scroll, setting maxHorizontalScrollPosition appropriately 
              var diffWidth:Number = measureWidthOfItems(0,0) - (unscaledWidth - viewMetrics.left - viewMetrics.right); 
              if (diffWidth <= 0) 
                    maxHorizontalScrollPosition = NaN; 
                    maxHorizontalScrollPosition = diffWidth; 
                    super.updateDisplayList(unscaledWidth, unscaledHeight); 
저작자 표시 비영리 변경 금지
Posted by 코멧'★

티스토리 툴바