I get Strings from a server that look something like this:
This is normal text followed by a link;
http://www.google.com
Links might also look like this;
http://google.com/whatever
This Strings are set as the text value in a spark TextArea. What I’d like to achieve is that
A. the text gets highlighted and
B. the user can click it and it opens in the systems browser.
Any help would be much appreciated!
Edit: Using the StyleableTextField throws a typerror on Flex 4.6.
I tried the simplest HTML text like this;
StyleableTextField(newsStoryArea.textDisplay).htmlText = "TextArea <b>bold</b><i>italic</i>."
which throws;
TypeError: Error #1034: Type Coercion failed: cannot convert
spark.components.supportClasses::StyleableStageText@fc3d0a1 to
spark.components.supportClasses.StyleableTextField.
Edit:
Nice one Adobe!
“htmlText in mobile skins
You cannot use the htmlText property in mobile applications.”
On the same page (http://help.adobe.com/en_US/flex/mobileapps/WS19f279b149e7481c698e85712b3011fe73-7fff.html#WS19f279b149e7481c7c94ce7c12b30152f48-7ffc), they say not to use TLF in mobile skins, so htmlText doesn’t work, and TLF shouldn’t be used.
Basically the two only options (unless there’s a third one I don’t know about) to format links properly are not to be used on mobile devices. Great!
Any recommendations?
If it throw
then your component use default skin which use StyleableStageText. And it not support htmlText property.
Based on name of your component “newsStoryArea” I can suppose that this is spark.components.TextArea. There are two mobile skins for spark.components.TextArea – default (I not remember its full name) and spark.skins.mobile.TextAreaSkin. Class spark.skins.mobile.TextAreaSkin use StyleableTextField which have htmlText property. So you can specify that your text area component use this skin. In result you will able use htmlText.
Also if textDisplay will be nonselectable then textDisplay will not dispath TextEvent.LINK (if you need this).