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>
分享到:
相关推荐
flex8表格控件,可以方便的实现表格的数据处理,并且里面附带了全面的例子,解决很多程序员的表格问题
flex3.5时间控件(含时分秒),亲测能用!
flex视频播放控件
Flex 上传文件控件 (带java服务端) 可以设置多文件还是单文件 设置上传大小 显示上传进度条
flex 时间选择控件,提供了时间的选择。。。
FLEX控件
java flex,flex通用分页控件
felx和springHibernate整合传递二进制数据到表中并在flex的dataGrid控件中显示的实践
flex控件事件flex控件事件flex控件事件flex控件事件
flex 控件 可与Vb6同行 flex 控件 可与Vb6同行 flex 控件 可与Vb6同行
flex拖拽树控件 添加 删除节点 拖拽生成节点
flex开发自定义控件
详解Flex4.0自定义控件的开发步骤以及注意事项
FLEX常用验证控件,flex的一些常用的验证
可以实现缩入折叠,翻转折叠效果,很不错哦!
控件可直接使用,内附使用demo,有问题留言给我,我们共同进步。
实现了Flex与Java的互操作,包含Flex控件的使用方法,Flex与Java的通讯。
flex 4 chart 控件, 可以做出比较漂亮的图
重载flex的Button, 使文本能够自动换行
这是一个基于Adobe Flash Builder 4开发的Flex多文件上传控件,这个是Flex源码,asp.net调用Flex的源码在另一个附件里