I wasn't clear before -- I don't know the width of the VBox beforehand. I was trying to figure out the minimum width I could make the VBox before I actually make it.
But the measureText() method worked perfectly for me, thanks. L. --- In flexcoders@yahoogroups.com, dorkie dork from dorktown <dorkiedorkfromdorkt...@...> wrote: > > Example code, > <mx:VBox width="100%"> > <mx:Text width="100%" /> > </mx:VBox> > > If you need to truncateToFit the text you can use the truncateToFit > property, more info... > http://blog.flexexamples.com/2008/01/26/truncating-text-in-the-flex-label-control-using-the-truncatetofit-property/ > > On Mon, Aug 30, 2010 at 12:06 AM, Alex Harui <aha...@...> wrote: > > > > > > > For mx:Label, you can try using measureText() on the parent unless the > > label will have different styles that will affect measurement. Then you'll > > have to add it and call validateNow() and call getExplicitOrMeasuredWidth(). > > > > But why not use mx:Text? Why do you have to get the width exactly? If you > > stretch an mx:Text to the width of the Vbox it sounds like it would suit > > your needs. > > > > > > > > On 8/29/10 2:06 PM, "Laurence" <lmacne...@...> wrote: > > > > > > > > > > > > > > Using ActionScript, I want to add a Label to a VBox. I know what text I > > want to put into the label (said text is read from an XML file), but of > > course, the program cannot know what the width of the label should be until > > after the text is read from that XML file. I want the label to be as wide > > as it needs to be, but not wider than the vBox I'm adding it to -- if that > > label will need to be wider than the given amount to display all the text, > > then I want to add a TextArea (with word-wrap turned on) so I can display > > all the text in that given width. > > > > My question is, how do I calculate the width of a label I'll need, when > > given a string of text? I do know the font-family and font-size the label > > will have. Is there an easy way to go from a string of text to the width > > that a label will need to be to display that text? > > > > Thanks, > > Laurence MacNeill > > Mableton, Georgia, USA > > > > > > > > > > > > > > -- > > Alex Harui > > Flex SDK Team > > Adobe System, Inc. > > http://blogs.adobe.com/aharui > > > > > > >