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:
textandhtmlTextParse 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:
appendTextto add chunk by chunk of the raw text and usingsetTextFormatto apply formatting (or do whatever else is necessary) after each append step.super.text.)selectionBeginIndexandselectionEndIndex(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.textandhtmlTextto return the newly formatted info, if you need the results somewhere else. I've usedhtmlTextto return a fully decorated xml string and kepttextfor accessing the raw text content, just like in a generic TextField.