Flex TLF框架

[color=red]TextFlow的textAlign样式的"justify"有何特点?[/color]
justify的中文解释为:调整使全行排满;使每行排齐;使齐行
请比较下边的两幅图:
textAlign = "left"&& whiteSpaceCollapse = "perserve":
[img]http://dl.iteye.com/upload/attachment/348065/80b12dea-8cfc-3973-aa5d-01a622087192.png[/img]
textAlign = "justify" && whiteSpaceCollapse = "perserve":
[img]http://dl.iteye.com/upload/attachment/348067/1026077d-9fea-30fd-ae0c-18211b5492bd.png[/img]

[color=red]TextFlow的whiteSpaceCollapse属性有啥影响?[/color]
4.1的API文档中对whiteSpaceCollapse的解释如下:
[quote]whiteSpaceCollapse:String (default = "collapse") — 指示是否应折叠或保留标记中的空白的 String。可能的值为 flashx.textLayout.formats.WhiteSpaceCollapse 类中的 WhiteSpaceCollapse.COLLAPSE 和 WhiteSpaceCollapse.PRESERVE。默认值为 WhiteSpaceCollapse.COLLAPSE。[/quote]

影响1:对显示结果的影响
两种设置的区别请比较下边两幅图:
textAlign = "justify" && whiteSpaceCollapse = "perserve":
[img]http://dl.iteye.com/upload/attachment/348067/1026077d-9fea-30fd-ae0c-18211b5492bd.png[/img]

textAlign = "justify" && whiteSpaceCollapse = "collapse":
[img]http://dl.iteye.com/upload/attachment/348081/67f1308c-e945-3bbd-b38a-920d29cac9db.png[/img]

影响2:对数据源处理的影响
当textFlow的文字数量比较多的时候,我们可能会想要给文字内容分行,并且加上缩进。
这种情况下,whiteSpaceCollapse = "collapse"会自动将用于缩进的空格给删掉,而whiteSpaceCollapse = "perserve"则保留这些空格。

[color=red]为何我调用TextConverter.importToFlow(text, TextConverter.TEXT_LAYOUT_FORMAT)返回的是null?[/color]
format类型为TextConverter.TEXT_LAYOUT_FORMAT时,text对应的XML的根节点必须含有名字空间:xmlns="http://ns.adobe.com/textLayout/2008"

[color=red]如何拿到每一行的内容?[/color]
可以通过TextFlowLine的absoluteStart和textLength属性来获取。
TextFlow解析出来完整的字符串可以通过下边两种方法获得:
1.通过组件(RichEditableText之类)的text属性(实现简单):
实例代码如下:

2.通过()

[color=red]如何获取被被选择的文本?[/color]
//初始化,需要将TextFlow.interactionManager赋值为EditManager
m_textFlow = TextConverter.importToFlow(textContent, TextConverter.TEXT_LAYOUT_FORMAT);
m_textFlow.interactionManager = new EditManager(new UndoManager());
.......
//获取的被选择文本
var editManager:EditManager = EditManager(m_textFlow.interactionManager);
var absoluteStart:int = editManager.getSelectionState().absoluteStart;
var absoluteEnd:int = editManager.getSelectionState().absoluteEnd;


[color=red]unfocusedSelectionFormat和inactiveSelectionFormat有啥区别?[/color]
文档中的解释如下:
[quote]inactiveSelectionFormat : SelectionFormat
当文本流 (TextFlow) 的窗口是非活动窗口时,该文本流的初始选择格式

unfocusedSelectionFormat : SelectionFormat
当该窗口是活动窗口但 TextFlow 中没有容器具有焦点时,Text Layout Framework 用于绘制选择内容的初始选择格式。[/quote]

[color=red]为啥设置的unfocusedSelectionFormat和inactiveSelectionFormat都没有生效?[/color]

[color=red]不能给TextFlow的Configuration的textFlowInitialFormat设置背景颜色的吗?[/color]
代码段如下:
	var config:Configuration = Configuration(TextFlow.defaultConfiguration).clone(); 	
var textFormat:TextLayoutFormat = new TextLayoutFormat();
textFormat.color = textColor.selectedColor;
textFormat.backgroundColor = textBackgroundColor.selectedColor;
textFormat.backgroundAlpha = 1;

config.textFlowInitialFormat = textFormat;
m_textFlow = TextConverter.importToFlow(textContent, TextConverter.TEXT_LAYOUT_FORMAT, config);

上边的textFormat.color都已经生效了,为啥textFormat.backgroundColor却没有生效?

[color=red]如何监听importToFlow里插入图片的事件?[/color]
只需要在调用TextConverter.importToFlow函数后,为其返回的TextFlow添加StatusChangeEvent.INLINE_GRAPHIC_STATUS_CHANGE事件的响应函数函数即可。
示例代码如下:

m_textFlow = TextConverter.importToFlow(textContent, TextConverter.TEXT_LAYOUT_FORMAT);
m_textFlow.addEventListener(StatusChangeEvent.INLINE_GRAPHIC_STATUS_CHANGE, handleInlineGraphicStatusChange);

[color=red]
如何通过InlineGraphicElement的instance获取此InlineGraphicElement的absolute start?[/color]
InlineGraphicElement提供了现成的函数:getAbsoluteStart()。

[color=red]为啥调用modifyInlineGraphic修改InlineGraphicElement不生效?[/color]
1.modifyInlineGraphic的第一个参数需要传入InlineGraphicElement的source而不是InlineGraphicElement的实例。
2.被修改的InlineGraphicElement需要处于被选中状态,可以通过给modifyInlineGraphic函数设置参数达到这一目的。
示例代码:
var editorManager:EditManager = EditManager(m_textFlow.interactionManager);
var inlineGraphic:InlineGraphicElement = event.m_resizedObj as InlineGraphicElement;
editorManager.modifyInlineGraphic(inlineGraphic.source, event.m_newWidth, event.m_newHeight, null, new SelectionState(m_textFlow, inlineGraphic.getAbsoluteStart(),
inlineGraphic.getAbsoluteStart() + 1));


search功能的实现:[/color]
            private function search(search:String):void
{
var len:int = search.length;
var pos:int = 0;
var r:Array = [];
do
{
if ((pos = editor.text.indexOf(search, pos)) != -1)
{
r.push(pos);
}
else
{
break;
}
}
while(pos += len);
for each(var index:int in r)
{
var txtLayFmt:TextLayoutFormat = editor.getFormatOfRange(null,
index,
index+search.length);
txtLayFmt.backgroundColor = 0xFCEE21;
editor.setFormatOfRange(txtLayFmt,
index,
index+search.length);
editor.setFocus();
}
//resultLabel.text= searchArray.length + " matches";
//if(searchArray.length > 0)
// searchArray[0].selected=true;
}


[color=red]图文混排参考链接:[/color]
[url]http://diding.iteye.com/blog/345239[/url]
[url]http://flex2.group.iteye.com/group/blog/358666[/url]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值