2011-05-23 70 views
1

在Mac OS X的Safari 4.0.2瀏覽器中,文本字段的內容是可滾動的。如何停止文本字段的滾動屬性?禁用Flex 3中文本字段的滾動屬性

我已經明確提到了它的寬度而不是高度。文本應該在可用區域內相應地調整大小。請有人提供解決方案。

+0

你使用什麼組件?一個Spark textInput?或者一個mx TextInput?或者完全不同的東西?你如何分享一些代碼? – JeffryHouser 2011-05-23 14:07:07

+0

你有沒有機會嘗試我發佈的答案?如果它可以幫助解決您的問題,您可以通過單擊^箭頭並將其標記爲已接受的答案,方法是單擊我答案旁邊的複選標記圖標。 – 2011-06-01 20:09:00

回答

0

我在過去對此要求使用此AutoResizeTextArea component。只需將autoResize屬性設置爲true即可。

<?xml version="1.0" encoding="utf-8"?> 
<mx:TextArea xmlns:mx="http://www.adobe.com/2006/mxml"> 
    <mx:Script> 
      <![CDATA[ 

       // auto resize setting 
       private var _autoResizable:Boolean = false; 

       // getter 
       [Bindable(event="changeAutoResize")] 
       public function get autoResize():Boolean 
       { 
        return _autoResizable; 
       } 

       // setter 
       public function set autoResize(b:Boolean):void 
       { 
        _autoResizable = b; 
        // if the text field component is created 
        // and is auto resizable 
        // we call the resize method 
        if (this.mx_internal::getTextField() != null && 
         _autoResizable == true) 
         resizeTextArea(); 
        // dispatch event to make the autoResize 
        // property bindable 
        dispatchEvent(new Event("changeAutoResize")); 
       } 

       // setter override 
       override public function set text(value:String):void 
       { 
        // calling super method 
        super.text = value; 
        // if is auto resizable we call 
        // the resize method 
        if (_autoResizable) 
         resizeTextArea(); 
       } 

       // resize function for the text area 
       private function resizeTextArea():void 
       { 
        // initial height value 
        // if set to 0 scroll bars will 
        // appear to the resized text area 
        var totalHeight:uint = 10; 
        // validating the object 
        this.validateNow(); 
        // find the total number of text lines 
        // in the text area 
        var noOfLines:int = this.mx_internal::getTextField().numLines; 
        // iterating through all lines of 
        // text in the text area 
        for (var i:int = 0; i < noOfLines; i++) 
        { 
         // getting the height of one text line 
         var textLineHeight:int = 
          this.mx_internal::getTextField().getLineMetrics(i).height; 
         // adding the height to the total height 
         totalHeight += textLineHeight; 
        } 
        // setting the new calculated height 
        this.height = totalHeight; 
       } 
      ]]> 
    </mx:Script> 
</mx:TextArea>