Flex HtmlButton 控件


package com
{
import flash.events.Event;
import flash.text.TextLineMetrics;
import mx.controls.Button;
import mx.core.UITextField;
import mx.core.mx_internal;
use namespace mx_internal;

public class HtmlButton extends Button
{
/**
* @private
* Storage for the htmlText property.
*/
private var _htmlLabel:String;

/**
* @private
* The value of the unscaledWidth parameter during the most recent
* call to DisplayList
*/
private var oldUnscaledWidth:Number;

/**
* @private
* This flag indicate htmlText changed for this component
*/
private var htmlLabelChanged:Boolean;

/**
* @private
* This flag indicate style changed for this component
*/
private var styleChangedFlag:Boolean = true;

/**
* @private
* This flag indicate tooltip set for this component
*/
private var toolTipSet:Boolean = false;

/**
* @private
* This label setter override for htmlLabel property with null
*/
override public function set label(value:String):void
{
super.label = value;

if (super.label != value)
_htmlLabel = null;
}

override public function get label():String
{
if(isHTML)
return _htmlLabel;
return super.label;
}

[Bindable("htmlLabelChanged")]
[CollapseWhiteSpace]
[Inspectable(category="General", defaultValue="")]
/**
* Specifies the text displayed by the Button control, including HTML markup that
* expresses the styles of that text.
* When you specify HTML text in this property, you can use the subset of HTML
* tags that is supported by the Flash TextField control.
*/
public function get htmlLabel():String
{
return _htmlLabel;
}


/**
* @private
*/
public function set htmlLabel(value:String):void
{
if (_htmlLabel != value)
{
_htmlLabel = value;

label = null;

htmlLabelChanged = true;

invalidateSize();
invalidateDisplayList();

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

/**
* @private
* This label setter override for toolTipSet property for this component
*/
override public function set toolTip(value:String):void
{
super.toolTip = value;

if (value)
toolTipSet = true;
else
toolTipSet = false;
}

/**
* @private
*/
private function get isHTML():Boolean
{
return _htmlLabel != null;
}

/**
* @private
*/
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth,unscaledHeight);

// If our width changed, reset the label text to get it to fit.
if (isHTML &&
(oldUnscaledWidth > unscaledWidth ||
textField.htmlText != htmlLabel ||
htmlLabelChanged||
styleChangedFlag))
{
textField.htmlText = _htmlLabel;
var lineMetrics:TextLineMetrics= measureHTMLText(_htmlLabel);
var d:Boolean = (lineMetrics.width + UITextField.TEXT_WIDTH_PADDING) > textField.width;

if (!toolTipSet)
{
if (d)
super.toolTip = textField.text;
else
super.toolTip = null;
}
}

oldUnscaledWidth = unscaledWidth;
htmlLabelChanged = false;
styleChangedFlag = false;
}

/**
* @private
* This function overrited only for styleChangedFlag
*/
override public function styleChanged(styleProp:String):void
{
styleChangedFlag = true;

super.styleChanged(styleProp);
}

/**
* This overrited function return TextLineMetrics based on htmlLabel property.
* If htmlLabel is not null, its return TextLineMetrics for htmlLabel.
* Otherwiset its return TextLineMetrics for label.
*/
override public function measureText(text:String):TextLineMetrics
{
if(isHTML)
return super.measureHTMLText(text);

return super.measureText(text);
}
}
}



<com:HtmlButton x="235" y="130">
<com:htmlLabel> <![CDATA[Hello<Font color="#FF0000">WorLd0000000</Font>]]></com:htmlLabel>
</com:HtmlButton>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值