Home » 程序开发 » Flash » TextArea自定义滚动条位置

TextArea自定义滚动条位置

发表评论 阅读评论
这是一个Flex的TextArea的自定义滚动条位置的效果,如果你看不到这个flash,请到文章页面查看!

自定义滚动的位置,必须覆盖updateDisplayList方法。

MyTextArea:

package
{
    import mx.controls.TextArea;

    public class MyTextArea extends TextArea
    {
        public function MyTextArea()
        {
        super();
        }

        override protected function updateDisplayList(unscaledWidth:Number, 
            unscaledHeight:Number):void
        {
            super.updateDisplayList(unscaledWidth, unscaledHeight);
            if (verticalScrollBar && verticalScrollBar.visible)
            {
                trace("viewMetrics: left =", viewMetrics.left, "ttop =", viewMetrics.top, 
                    "tright =", viewMetrics.right, "tbottom =", viewMetrics.bottom);
                verticalScrollBar.move(0, viewMetrics.top);
                if(horizontalScrollBar)
                {
                    horizontalScrollBar.move(viewMetrics.right, height - viewMetrics.bottom);
                }
                this.textField.move(viewMetrics.right, viewMetrics.top);
            }
        }
    }
}

MXML:

<mx :Application xmlns:mx = "http://www.adobe.com/2006/mxml" 
    preloader = "cn.lite3.preloaders.MyLoading" layout = "absolute" 
    xmlns:ns1 = "cn.lite3.component.*" width = "800" height = "300" >

    <mx :Text y = "28" text = "TextArea 滚动条在左边,其他带滚动条的也可以用这样的方法更改的" 
        width="563" textAlign="center" fontWeight="bold" fontSize="16" 
        color="#FFFFFF" horizontalCenter="0"/>
    <ns1 :MyTextArea id = "ll" x = "10" y = "60" width = "780" height = "230" 
        verticalScrollPolicy = "on" 
        text = "这是一个滚动条在左边的文本框, 要让自定义滚动条的位置,必须覆盖 updateDisplayList 方法
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void" 
        textAlign="left" fontSize="16" color="#0CCCF5" wordWrap="false">
    </ns1>
</mx>
标签: , , ,

  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.
回到顶部