1

Is there an easy way to compare two TextFlow objects with each other? I have two text flow objects that are created with TextConverter.importToFlow() and want to check if they are equal or not. Only way I found so far is to use TextConverter.export() to export them to a string then compare which seems bit convoluted...

Sang Park
  • 382
  • 2
  • 17
  • 2
    No experience on this one so not posting it as an answer but does getText() work, as in textFlow1.getText() == textFlow2.getText(). – shaunhusain Feb 10 '12 at 01:05
  • hmm that seems to work. although I wanted something more in line of textflow1.equals(textflow2) but i guess that will do. – Sang Park Feb 10 '12 at 01:14
  • Have you tried `ObjectUtil.compare(textFlow1, textFlow2)`? No idea if it'll work, but I guess it should. – RIAstar Feb 10 '12 at 09:07
  • Just tested it: doesn't work. I think every TLF element gets a unique ID, so when they are compared they are marked as different because of this ID. – RIAstar Feb 10 '12 at 09:30
  • I went with using getText(). @shaunhusain can you post it as an answer so i can accept it? – Sang Park Feb 10 '12 at 18:36

2 Answers2

4

Using getText() on the TextFlow objects returns a string representation of the contents, the string comparisons should give you the equality value between the two TextFlow objects assuming formatting or other elements within the TextFlow are not to be considered.

textFlow1.getText()==textFlow2.getText()

is the simplest solution I can see from the docs.

shaunhusain
  • 19,630
  • 4
  • 38
  • 51
0

If you need to compare text with styles, you can use:

var s1:String = TextConverter.export(textFlow1, TextConverter.TEXT_LAYOUT_FORMAT, ConversionType.STRING_TYPE) as String;
var s2:String = TextConverter.export(textFlow2, TextConverter.TEXT_LAYOUT_FORMAT, ConversionType.STRING_TYPE) as String;
s1 == s2;