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?
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
and htmlText
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,
<span class="sometext" animation="true">Info</span>
would be translated to an object like this:
{ text:"Info", clazz="sometext", animation:true };
appendText
to add chunk by chunk of the raw text and using setTextFormat
to apply formatting (or do whatever else is necessary) after each append step. super.text
.)selectionBeginIndex
and selectionEndIndex
(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
and htmlText
to return the newly formatted info, if you need the results somewhere else. I've used htmlText
to return a fully decorated xml string and kept text
for accessing the raw text content, just like in a generic TextField.