小小菜鸟的web菜园子

web开发学习。好记性不如烂笔头。每天进步一点点!

导航

检测TextArea组件文本行数。

getTextField()numLines 属性.
示例:


代码:
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/05/08/determining-the-number-of-lines-in-a-textarea-control-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout
="vertical"
        verticalAlign
="middle"
        backgroundColor
="white">

    
<mx:Script>
        
<![CDATA[
            import mx.utils.StringUtil;

            private function textArea_change(evt:Event):void {
                callLater(updateStats, [evt]);
            }

            private function updateStats(evt:Event):void {
                var nLines:uint = textArea.mx_internal::getTextField().numLines;
                var nChars:uint = textArea.length;
                var str:String = "{0} characters; {1} lines";
                panel.status = StringUtil.substitute(str,
                                    nChars,
                                    nLines);
            }
        
]]>
    
</mx:Script>

    
<mx:String id="str" source="lorem.txt" />

    
<mx:ApplicationControlBar dock="true">
        
<mx:Form styleName="plain">
            
<mx:FormItem label="width (%):">
                
<mx:HSlider id="slider"
                        minimum
="50"
                        maximum
="100"
                        value
="100"
                        liveDragging
="true"
                        snapInterval
="1"
                        tickInterval
="10" />
            
</mx:FormItem>
        
</mx:Form>
    
</mx:ApplicationControlBar>

    
<mx:Panel id="panel"
            percentWidth
="{slider.value}"
            height
="100%">
        
<mx:TextArea id="textArea"
                htmlText
="{str}"
                condenseWhite
="true"
                width
="100%"
                height
="100%"
                change
="textArea_change(event);"
                resize
="textArea_change(event);" />
    
</mx:Panel>

</mx:Application>

posted on 2008-05-10 12:20  『小小菜鸟』  阅读(2439)  评论(1编辑  收藏  举报