我怎样才能得到一个MX:textarea的高度是一样的内容 [英] How can I get a mx:textarea height to be the same as the content

查看:240
本文介绍了我怎样才能得到一个MX:textarea的高度是一样的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文本区域的初始高度比内容大得多,我无法找到使它总是相同的高度的文本内容的一种方法:

 < MX:文本ID =文本区域的borderStyle =实WIDTH =100%将wordWrap =真正的选择=假backgroundAlpha =0focusAlpha = 0文本=这是一个小测试/>
 

给出了一个边界框,很多身高超过必要的。

这也给了unintential问题,如果你有一个环节'鼠标悬停在内容中的链接时触发无处链接附近。

 < MX:脚本>
<![CDATA [
公共职能的OnInit():无效
{
    VAR风格:样式表=新的样式表();

    VAR ALINK:对象=新的对象();
    aLink.color =#0000FF;

    VAR aHover:对象=新的对象();
    aHover.color =#00FF00;
    aHover.textDecoration =下划线;

    style.setStyle(答:悬停,aHover);
    style.setStyle(答:链接,ALINK);

    textarea.styleSheet =风格;
}
]]≥
< / MX:脚本>


< MX:文本ID =文本区域WIDTH =100%将wordWrap =真的borderStyle =坚实的选择=假backgroundAlpha =0focusAlpha =0>
    < MX:的htmlText>
    < [CDATA [< A HREF =事件:HTTP://www.adobe.com'>导航到Adobe.com< / A>这是测试什么都没有真正]]>
    < / MX:的htmlText>
< / MX:文本>
 

文本组件犯规从这个苦,但我不能样式表附加到文本组件。

希望有人可以提供帮助。或者是有一些其他的成分,我可以用在那里我可以添加一个样式表stylise锚标记。

我发现这个重写的TextArea.as源,如果我重写它,并删除了2×事半功倍几乎工程,但不幸的是它意味着内容犯规得到较大时,它需要和垂直滚动,而不是,所以其几乎有:

 覆盖保护功能的措施():无效
{
    super.measure();

    使用measuredMinWidth = DEFAULT_MEASURED_MIN_WIDTH;
    是measuredWidth = DEFAULT_MEASURED_WIDTH;
    // TextArea中是最低的两行文本
    使用measuredMinHeight =是measuredHeight = 2 * DEFAULT_MEASURED_MIN_HEIGHT;
}
 

解决方案

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

 包
{
    进口对象类型:flash.events.Event;
    进口的flash.text.StyleSheet;

    进口mx.controls.Text;

    进口mx.core.mx_internal;

    使用命名空间mx_internal;

    公共类的StyledText扩展文本
    {
    公共职能的StyledText()
    {
    		超();
    }

    私人VAR _styleSheet:样式表= NULL;

    [可绑定(stylesheetChanged)]
    公共函数来获取的styleSheet():样式表{
    返回_styleSheet;
    }

    公共功能集的styleSheet(价值:样式表):无效{
    _styleSheet =价值;

    如果(textfield的情况){
    textField.styleSheet = _styleSheet;
    }

    则dispatchEvent(新的事件(stylesheetChanged));
    }

    覆盖保护功能createChildren():无效{
    super.createChildren();

    // textField的是在createChildren创建
    //标签类的方法
    如果(textField的&安培;&放大器;的styleSheet){
    textField.styleSheet = _styleSheet;
    }
    }

    }
}
 

然后就可以使用该组件像这样:

 < XML版本=1.0编码=UTF-8&GT?;
< MX:应用的xmlns:MX =htt​​p://www.adobe.com/2006/mxml布局=绝对的xmlns:NS1 =*preinitialize =的OnInit()>
    < MX:脚本>
    <![CDATA [
    公共职能的OnInit():无效
    {
        VAR风格:样式表=新的样式表();

        VAR ALINK:对象=新的对象();
        aLink.color =#0000FF;

        VAR aHover:对象=新的对象();
        aHover.color =#00FF00;
        aHover.textDecoration =下划线;

        style.setStyle(答:悬停,aHover);
        style.setStyle(答:链接,ALINK);

        text.styleSheet =风格;
    }
    ]]≥
    < / MX:脚本>


    &所述; NS1:的StyledText的id =文本×=0Y =79>
    < NS1:的htmlText>
    < [CDATA [< A HREF =事件:HTTP://www.adobe.com'>导航到Adobe.com< / A>这是测试什么都没有真正]]>
    < / NS1:的htmlText>
    < / NS1:的StyledText>

< / MX:用途>
 

The initial height of a text area is much larger than the content, I cannot find a way of making it always the same height as the text content:

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

Gives a bordered box that is much taller than needed.

This also gives an unintential problem if you have links within the content in that a link 'mouseover' is triggered when nowhere near the link.

<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>

The Text component doesnt suffer from this, but I cannot attach a stylesheet to a text component.

Hoping someone can help. Or is there some other component I can use where I can add a stylesheet to stylise anchor tags.

I found this overridable in the TextArea.as source and if I override it and remove the "2 x" multiplier it almost works but unfortunately it means that the content doesnt get bigger when it needs to and vertically scrolls instead, so its almost there:

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;
}

解决方案

If you extend Text, you can add a getter/setter that allows you to set the styleSheet of the underlying UITextField object.

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;
    		}
    	}

    }
}

Then you can use the component like so:

<?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>

这篇关于我怎样才能得到一个MX:textarea的高度是一样的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆