我在格式化文本字段时遇到问题。我有按钮 + 和 - 来调整文本的大小。TextField 类具有用于新文本格式的属性 defaultTextField。当我更改 defaultTextFormat 大小属性时 - 整个文本的大小都会发生变化。我到处寻找解决方案,但还没有找到。文本编辑器 WISWYG(我不确定名称是否正确)在我遇到问题时只需更改 defaultTextFormat 属性即可正常工作。可能是因为 flash 和 AIR 之间的差异(flash 上的编辑器和我的 AIR 上的应用程序)。请帮忙。
这里设置/获取TextFormat的代码:
public function set selectionTextFormat(value:TextFormat):void {
var begin:int = _textField.selectionBeginIndex;
var end:int = _textField.selectionEndIndex;
if (begin == end)
{
_textField.defaultTextFormat = value;
}
else
{
_textField.setTextFormat(value, begin, end);
}
}
public function get selectionTextFormat():TextFormat
{
var begin:int = _textField.selectionBeginIndex;
var end:int = _textField.selectionEndIndex;
if (begin == end)
{
return _textField.defaultTextFormat;
}
return _textField.getTextFormat(begin, end);
}
以及更改格式的代码:
private function setFormat(property:String, value:*):void
{
var tf:TextFormat = TextFormatter.TF.selectionTextFormat;
tf[property] = value;
TextFormatter.TF.selectionTextFormat = tf;
}
编辑:用于说明的 DROPBOX 上的图像: https ://dl.dropboxusercontent.com/u/237572639/Capture.PNG
编辑 2:我需要的图像(代码完全一样!)(所见即所得编辑器) https://dl.dropboxusercontent.com/u/237572639/WYSIWYG.PNG