tags:

views:

48

answers:

1
package {
 import mx.controls.LinkButton;
 import flash.text.TextLineMetrics;

 public class multiLineLinkButton extends LinkButton {
      override protected function createChildren():void {
           super.createChildren();
           if (textField){
                textField.wordWrap = true;
                textField.multiline = true;

           }
      }

      override public function measureText(s:String):TextLineMetrics {
           textField.text = s;
           var lineMetrics:TextLineMetrics = textField.getLineMetrics(0);
           lineMetrics.width = textField.textWidth;
           lineMetrics.height = textField.textHeight;


           return lineMetrics;
      }
 }

my issue here is if you use this component you will see that the text is bunched up into a very small area. It does not fill the entire width of the linkButton. Anyone know why this is happening?

A: 

The container is probably not wide enough. Set the container percentWidth to 100 and see if it fixes your problem. You can also set the LinkButton to a fixed width and see if that helps.

Robusto
something like this?`textField.percentWidth = 100;`in the custom component? that doesnt seem to work.
Adam
No, I said put the percentWidth on the container. Try setting the LinkButton's width property to 80 or 100, just to see if you can get a width on it at all.
Robusto
when i manually add a width value to the linkButton it gives it the proper dimensions, but the text is still bunched up.
Adam
Oh, I see what you're doing. Duh, I missed it the first time I looked at your code. I'm pretty sure you shouldn't be trying to set the lineMetrics dimensions. Those aren't marked read-only, but I think they should be. They just report on the dimensions of the text in that particular line. What exactly are you trying to gain by setting this? And if you do set it, you should do a validateNow() right after you get the lineMetrics, or else they will not be accurate.
Robusto
in the component the textField.textWidth is always giving a value around 95. I think the issue is that it's not getting the proper width of the textField
Adam
I found this component somewhere online. I'm not sure what everything does. but setting the textlinemetrics does do something so it must not be read only.
Adam