如何跟踪 AS3 中动态文本字段中的文本部分
我希望能够将非样式属性应用于 TextField 中的文本部分。例如,角色 30-45 将被设置为在某个方向上进行动画处理。
由于此字段是可编辑的,因此如果以任何方式编辑文本,则字符 30-45 可能不再是 30-45。
谁能想出一种优雅的方式来跟踪哪些角色应用了属性?
I want to be able to apply non-style attributes to sections of text in a TextField. For example characters 30-45 will be set to animate in a certain direction.
As this field is editable characters 30-45 may no longer be at 30-45 if the text is edited in any way.
Can anyone think of an elegant way to keep track of which characters had the attributes applied to them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有一个类似的项目,最终扩展了 TextField 类来满足我的需求。这是要做什么的简短描述 - 恐怕我的实际代码是保密的:
text
和htmlText
的 setter解析这些 setter 中的任何内容到自定义对象的数组中。每个对象都包含原始文本块和适用于它们的元数据(格式、注释等)。
例如,
将被转换为这样的对象:
appendText
逐块添加原始文本并使用setTextFormat
应用来呈现实际的文本输出在每个附加步骤之后进行格式化(或执行其他必要的操作)。super.text
。)selectionBeginIndex
进行处理的,selectionEndIndex
(计算对象数组的原始文本中的字符数,以找出哪些块受到影响)。直接在容器对象中添加或替换新文本,然后使用步骤 3. 刷新 TextField 中的整个文本。text
和htmlText
的 getter 以返回新格式化的信息。我使用htmlText
返回一个完全修饰的 xml 字符串,并保留text
用于访问原始文本内容,就像在通用 TextField 中一样。I've had a similar project and ended up extending the TextField class to fit my needs. Here's a short description of what's to do - my actual code is confidential, I'm afraid:
text
andhtmlText
Parse any content from these setters into an array of custom objects. Each of these objects contains raw text chunks and the metadata that applies to them (format, comments, etc.).
For example,
would be translated to an object like this:
appendText
to add chunk by chunk of the raw text and usingsetTextFormat
to apply formatting (or do whatever else is necessary) after each append step.super.text
.)selectionBeginIndex
andselectionEndIndex
(count the number of characters in the raw text of your object array to find out which chunks are affected). Add or replace the new text directly within the container objects, then use step 3. to refresh the entire text in the TextField.text
andhtmlText
to return the newly formatted info, if you need the results somewhere else. I've usedhtmlText
to return a fully decorated xml string and kepttext
for accessing the raw text content, just like in a generic TextField.