This content has been marked as final. Show 4 replies
I don't think you can get accurate position info for individual characters.
It would be better to have the text control populated from a collection, perhaps with two fields like "summary" and "detail". Then update the text control with the "detail" field contents. If you no longer want the LinkButton to appear, you can set its "visible" and "includeInLayout" properties to false. If you still want it to display, perhaps you are thinking of changing the LinkButton text to something like "Display Summary", you can do that, and if you are using Flex's auto layout capabilities, the LinkButton will be moved when the detailed text displays.
From an internationalization perspective, absolute positioning of most things having localizable data is a bad idea as well.
When you say "using Flex's auto-layout capabilities," how do you see them applying in this case? What I'm trying to achieve is something like the following:
Here is the first sentence. Here is the second -- it could
be of any length, so we need to be able to cut it [LinkButton]
... where LinkButton is a control that takes some action. I've tried adding text controls for each "word" and then laying them out in a Repeater-like way, but with scaling, I'm getting strange behavior.
The requirement is what it is -- words followed with an actionable inline control. Does anyone have any ideas that'd work?
You don't need to cut the text, just have two versions of the text (summary and detail). If displayed in a TextArea it can wrap if necessary. To the right of the TextArea will be the LinkButton. Have the TextArea and the LinkButton in an HBox and the auto layout capabilities of the HBox should do the trick. Here is an example, though this code would need tweaking for your overall layout and circumstances:
Hm, thanks, but that just places the LinkButton next to the TextArea control, beside and outside of it, not "inside" (or really over) it, as my example should've implied.
I think I've found a workable solution -- see below, where myCanvas is some Canvas control already defined in MXML somewhere, and myText is a Text control already defined (and populated) as well:
var numberOfLines:int = myText.mx_internal::getTextField().numLines;
var lineMetrics:TextLineMetrics = myText.getLineMetrics(numberOfLines - 1);
var targetX:int = lineMetrics.width + 10;
var targetY:int = (numLines - 1) * lineMetrics.height;
var myLinkButton:LinkButton = new LinkButton();
myLinkButton.label = "More...";
Still testing, but TextLineMetrics seems to have done the trick.
If anyone has a better approach, let me know! Thanks much.