如何扩展LinkBut​​ton以允许Flex中的HTML文本?

时间:2022-08-22 21:21:40

I am feeding the label to my LinkButton directly from a string I receive from a Google API that puts html to format the label.

我直接从我从Google API收到的字符串中将标签提供给我的LinkBut​​ton,该API将html格式化为标签。

I want to extend linkbutton to allow this. I wrote a class myself to allow html text for the label and that aspect of it works but now the background that appears when you hover is way too big. I tried to override measure() to fix this but I didn't have a clue how. Here is the class I wrote:

我想扩展linkbutton来允许这个。我自己写了一个课程,允许标签的html文本和它的方面工作,但现在你悬停时出现的背景太大了。我试图覆盖measure()来解决这个问题,但我不知道如何。这是我写的课:

package com.kranichs.components
{
    import mx.controls.LinkButton;

    public class HTMLLinkButton extends LinkButton
    {
        protected var _isHTML:Boolean;

        public function HTMLLinkButton()
        {
            super();
        }

        [Bindable]
        public function set isHTML(value:Boolean):void
        {
            _isHTML = value;
        }
        public function get isHTML():Boolean
        {
            return _isHTML;
        }

        override protected function updateDisplayList(unscaledWidth:Number,
                                                  unscaledHeight:Number):void
        {
            super.updateDisplayList(unscaledWidth, unscaledHeight);
            if(_isHTML)
            {
                textField.htmlText = label;
            }
        }



    }
}

1 个解决方案

#1


the measure() function is the key.

measure()函数是关键。

Assuming you are using a flex compatibility version >= 3.0, the key line is in Button.measure():

假设您使用的是flex兼容版本> = 3.0,则键行位于Button.measure()中:

var lineMetrics:TextLineMetrics = measureText(label);

You need to change this to something like:

您需要将其更改为:

var lineMetrics:TextLineMetrics = _isHTML ? measureHTMLText(label) : measureText(label);

You will probably need to copy the measure function from button into your class and make this change.

您可能需要将度量函数从按钮复制​​到您的类中并进行此更改。

If you do that, you will most likley need to import the internal namespace, like this:

如果你这样做,你最需要导入内部命名空间,如下所示:

import mx.core.mx_internal;

use namespace mx_internal;

#1


the measure() function is the key.

measure()函数是关键。

Assuming you are using a flex compatibility version >= 3.0, the key line is in Button.measure():

假设您使用的是flex兼容版本> = 3.0,则键行位于Button.measure()中:

var lineMetrics:TextLineMetrics = measureText(label);

You need to change this to something like:

您需要将其更改为:

var lineMetrics:TextLineMetrics = _isHTML ? measureHTMLText(label) : measureText(label);

You will probably need to copy the measure function from button into your class and make this change.

您可能需要将度量函数从按钮复制​​到您的类中并进行此更改。

If you do that, you will most likley need to import the internal namespace, like this:

如果你这样做,你最需要导入内部命名空间,如下所示:

import mx.core.mx_internal;

use namespace mx_internal;