tags:

views:

322

answers:

1

I basically want to make things easier by just looping LinkButtons instead of making textfields because the linkbuttons have the rollovers already programmed.

But I have a lot of text and it just keeps going. I want it to wrap like I can do with textfields.

Thanks

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 = 700;
           lineMetrics.height = textField.textHeight;


           return lineMetrics;
      }
 }

}

This is the component, but like I said everything is automatically centered.

I've tried paddingLEFT =0; and trying to setStyle("paddingLEFT", 0); but those methods don't work.

var test:multiLineLinkButton = new multiLineLinkButton();

        test.label = "sdfdsfdsfdsfsdfsdfsdfdsfsdfdsfdsdsfdsfdsfdffsdfdsfdfdsfdsfdsfdsfdsfdsfsdfdsfdfdsfdfdsfdsfsdfsdfsdf";
        test.setStyle("textAlign","left");

        var metrics:TextLineMetrics = measureText(test.label);

        trace(metrics.height);
        myCanvas.addChild(test);

so metrics.height is giving me a height of 14, which i believe is a single line even though it wraps.

+1  A: 

This guy did it: http://ooine.com/index.php/2009/10/12/flex-linkbutton-word-wrap/

FYI, this was the first hit on Google for the search term "flex linkButton word wrap"

invertedSpear
Thanks. Which leads me to another question. How do you utilize components in the script tags/ actionscript
Adam
got it var hey:multiLineLinkButton = new multiLineLinkButton();Thanks
Adam
I tried the code and it works somewhat. For some reason the boundaries of the text are around 50 pixels wide. I increased the .width but all it did was increase the rollover box width and not the actual text.
Adam
maybe some kind of padding?
invertedSpear
var lineMetrics:TextLineMetrics = textField.getLineMetrics(0); lineMetrics.width = 700; lineMetrics.height = textField.textHeight;I just added my own 700 width... but now how do I get it aligned to the LEFT, autosize isnt working for me
Adam
alignment is a style, so in mxml it would be `textAlign="left"` in AS it would be `setStyle("textAlign","left");` Stack overflow tip: in comments you can highlight your code like `this` by using tick marks (the little mark thats next to the [1] key and usualy shares `~`. At least it's that way on U.S. keyboards
invertedSpear
Thanks that did it.`var metrics:TextLineMetrics = measureText(txt.label);``trace(metrics.height);`this normally would give me the height of a Text component. But I'm only given the value of 14. How can I get the height of the textfield in the custom component and bring back to my main app
Adam
Add a code example to your original question so I can see the code of your custom component. It might be as easy as giving an ID (such as custText) to the text component and building a method that returns custText.height
invertedSpear
ok thanks I've added the code above
Adam