This content has been marked as final. Show 6 replies
I believe the best way would be to create a hyperlink and assign it to a textField. Such as:
theTextField.htmlText = “<a href=’event:linkContent’>linkText</a>”;
private function linkListener(e:TextEvent):void
“The linkContent string typically identifies an ActionScript operation to be carried out when the link is clicked.”
– Essential ActionScript 3.0 p.577
Thanks for the reply. This wil provide one link for the whole textField. I want to avoid creating a textField for each word, since it's probably slow and I'll have to do the work that the text renderer usually does, including word spaces, line wrap, etc.
I want to use a small number of textfields for many lines of text, and then detect which word the mouse moved over.
I like myIP's idea. You assign a link to each word and add the whole thing to the HTMLtext property. Don't think you could make individual words or letters clickable without them being HTMLtext. This would result in a lot of html tags, though I see no other way. Plain text have no events associated with them.
getLineMetrics returns a line of text, not individual letters or words.
Consider giving us more details about what you are trying to accomplish by having the text 'clickable', and someone may have an idea for you.
"This wil provide one link for the whole textField"
It could if you want it to be that way. It can also provide one link for each word or letter.
Remember you can add multiple <a> tags to a textfield. Such as below:
theTextField.htmlText = “<a href=’event:linkContent’>Adobe</a><a href=’event:linkContent’>Flex</a>”<a href=’event:linkContent’>Builder</a> 3";
Does that help? "Adobe", "Flex" and "Builder" has their own links. The "3" does not have a link. Then you can have unique "linkContents" for each word, so that the listener will know what word or letter was clicked.
I am not sure if this text will be loaded on a flat(static) or dynamic file. If its flat you could manually add each <a> tag where its needed. If its dynamic you would need to write a function or class to insert <a> tags where its needed.
Let me know how it goes.
This is dynamic text, or even text provided via a remote object.
And yes, I can make each word into a hypertext link. It's a bit clumsy and may have worse performance.
This application is text-heavy, so it matters.
Yes, "line metrics" describes the bounding box of a line of text, so it's only part of the solution, if there is one.
I'm investigating all of the properties and methods of the TextArea component. The Text component won't do it.
What I really want to do is catch "mouse move" events, and then "look up" in the underlying text object, what word or is under the cursor.
I'll report my results.
I have since moved on to using Text Layout Framework, which does everything that I need.
More about this soon.