English 中文(简体)
我怎样才能得到一个mx: textarea高度是一样的内容
原标题:
  • 时间:2009-04-08 21:28:48
  •  标签:

一个文本区域的初始高度远远大于内容,我不能找到一种方法使它总是相同的高度文本内容:

<mx:TextArea id="textarea" borderStyle="solid" width="100%" wordWrap="true" selectable="false" backgroundAlpha="0" focusAlpha="0" text="this is a little test" />

给出了一个与框比需要高多了。

这也给一个unintential问题如果你有在内容的链接,链接鼠标移至离链接时触发。

<mx:Script>
<![CDATA[
public function onInit():void
{
    var style:StyleSheet = new StyleSheet();

    var aLink:Object = new Object();
    aLink.color = "#0000FF";

    var aHover:Object = new Object();
    aHover.color = "#00FF00";
    aHover.textDecoration = "underline";

    style.setStyle( "a:hover", aHover );
    style.setStyle( "a:link", aLink );

    textarea.styleSheet = style;
}
]]>
</mx:Script>


<mx:TextArea id="textarea" width="100%" wordWrap="true" borderStyle="solid" selectable="false" backgroundAlpha="0" focusAlpha="0" >
    <mx:htmlText>
    <![CDATA[<a href= event:http://www.adobe.com >Navigate to Adobe.com.</a> this is testing nothing at all really]]>
    </mx:htmlText>
</mx:TextArea>

文本组件不受这个,但是我不能将样式表附加到一个文本组件。

希望有人可以帮助你。还是有其他一些组件可以使用,我可以添加一个样式表程式化锚标记。

我发现这个重写的文本区域。源和如果我覆盖和删除“2 x”乘数几乎工作但不幸的是这意味着内容并不变大,当它需要和垂直滚动相反,所以它几乎有:

override protected function measure():void
{
    super.measure();

    measuredMinWidth = DEFAULT_MEASURED_MIN_WIDTH;
    measuredWidth = DEFAULT_MEASURED_WIDTH;
    // TextArea is minimum of two lines of text
    measuredMinHeight = measuredHeight = 2 * DEFAULT_MEASURED_MIN_HEIGHT;
}
最佳回答

如果你扩展文本,您可以添加一个getter / setter,允许您设置的样式表底层UITextField对象。

package
{
    import flash.events.Event;
    import flash.text.StyleSheet;

    import mx.controls.Text;

    import mx.core.mx_internal;

    use namespace mx_internal;

    public class StyledText extends Text
    {
        public function StyledText()
        {
            super();
        }

        private var _styleSheet:StyleSheet = null;

        [Bindable("stylesheetChanged")]
        public function get styleSheet():StyleSheet {
            return _styleSheet;
        }

        public function set styleSheet(value:StyleSheet):void {
            _styleSheet = value;

            if ( textField ) {
                textField.styleSheet = _styleSheet;
            }

            dispatchEvent(new Event("stylesheetChanged"));
        }

        override protected function createChildren():void {
            super.createChildren();

            //textField is created in the createChildren 
            //method of the Label class
            if ( textField && styleSheet ) {
                textField.styleSheet = _styleSheet;
            }
        }

    }
}

然后您可以使用组件一样:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ns1="*" preinitialize="onInit()">
    <mx:Script>
    <![CDATA[
    public function onInit():void
    {
        var style:StyleSheet = new StyleSheet();

        var aLink:Object = new Object();
        aLink.color = "#0000FF";

        var aHover:Object = new Object();
        aHover.color = "#00FF00";
        aHover.textDecoration = "underline";

        style.setStyle( "a:hover", aHover );
        style.setStyle( "a:link", aLink );

        text.styleSheet = style;
    }
    ]]>
    </mx:Script>


    <ns1:StyledText id="text" x="0" y="79">
        <ns1:htmlText>
        <![CDATA[<a href= event:http://www.adobe.com >Navigate to Adobe.com.</a> this is testing nothing at all really]]>
        </ns1:htmlText>
    </ns1:StyledText>

</mx:Application>
问题回答

我还没试过你尝试什么,但这个链接看起来可能帮助:

< a href = " http://www.adobe.com/cfusion/communityengine/index.cfm?事件= showdetails&postId = 13628 &productid = 2”rel = " http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&postId=13628&productId=2 nofollow noreferrer " > < / >。

基于Bedwyr s链接,我想我应该试着recalcing高度自己和这个似乎工作得很好(没有发现任何不良副作用,但可能有):

this.addEventListener( Event.CHANGE, onReMeasure );
this.addEventListener( Event.RESIZE, onReMeasure );

override protected function measure():void
{
        super.measure();

        measuredMinWidth = DEFAULT_MEASURED_MIN_WIDTH;
        measuredWidth = DEFAULT_MEASURED_WIDTH;

        var lm:TextLineMetrics = getLineMetrics( 0 );
        measuredMinHeight = measuredHeight = DEFAULT_MEASURED_MIN_HEIGHT;
}

private function onReMeasure( eventObj:Event ):void
{
    var ht:Number = 0;
    for( var n:int = 0; n < textField.numLines; n++ )
    {
        ht += textField.getLineMetrics(n).height;
    }
    ht += 10;   // padding

    height = ht;
    validateNow();
}




相关问题
热门标签