views:

310

answers:

2

Hi, i've a text with a very long list of words to highlight and calling setTextFormat() one for each word takes ages. There's some way to speedup this operation ? i've tried with a TextField not instantiate in the DisplayObject's list, to bypass the rendering stage but i've founded that the performance are the same. Any ideas ?

A: 

if its a htmlText and the words that you wanna to highlight are put in tags like <strong> you should look at the StyleSheet Object you can define its styles by loading a css file or you can assign the styles like this:

var style:StyleSheet = new StyleSheet();
var strong:Object = new Object(); 
strong.textDecoration = "underline";
style.setStyle("strong", strong);
antpaw
Thanks for your reply. I've checked htmlText and i know that it's way faster then setTextFormat() but the problem is that i have to reapply colors when user changes the text and using htmlText i have to blank the area and replace htmlText with a new version and the user see the TextArea blink, and the text moved to the end. Using setTextFormat() i can change only small part of the text during text changes
wezzy
you could change this bug into a feature, just fadeout nicely the text, change it, and fade it in again. but i don't really understand how the user can change a htmlText.
antpaw
well the user interact with a component similar to a standard Flex TextArea so it can change the content by typing or using cut/paste. I have a listener for the CHANGE event that update the inner textField to reflect content changes. If the user write something i have to colorize the text again and using htmlText it means that i have to pass a new string to htmlText
wezzy
A: 

I'm going to strongly suggest you take a look at the Text Layout Framework's new mode of handling rich text styling.

Essentially, the TLF has a TextFlow object that contains a model of your text, including all relevant span-specific formatting. This is distinct from the "view" portion of text display, which would be managed (in your case of edit-able text) by a separate flow composer and EditManager.

Thus, you can perform formatting transformations on wide swaths of the text model, and only have the view re-draw itself on command at the very end.

ZackBeNimble
Hi, i've converted the code using Text Layout Framework, my code takes a Vector of token and for each token callsvar selection:SelectionState = new SelectionState(this._textFlow, begin, end, normalFormat);where begin, and end are two integers that represent the area to colorize and IEditManager(_textFlow.interactionManager).applyLeafFormat(format, selection);apply my format (an instance of TextLayoutFormat). Everything seems to work but it's 10 times slower than the previous version. I've done any error ? are there any clever solution (i'm sure about it...) ?
wezzy