Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 08-02-2006, 06:47 PM   #1
astgtciv
Resu Deretsiger
 
astgtciv's Avatar
 
Join Date: Jul 2005
Location: St-Petersburg, Russia
Posts: 2,329
Post [newbie] A Label with width matching text

How do you create an mx.controls.Label whose width would automatically
adjust when its .text is reset? Or, at least, how do you figure out which width to set the Label to once its .text is reset? The only thing I came up so far is "label.textWidth + 12" Thanks!
__________________
overstream.net: add subtitles to online videos (youtube, vimeo, blip.tv...).
astgtciv is offline   Reply With Quote
Old 08-02-2006, 07:41 PM   #2
flexy
Everything about me's...
 
Join Date: Aug 2006
Location: UK
Posts: 198
Default

As far as I can see, you don't need to specify a width for the Label component. It should simply expand or contract to accomodate this string you bind to it.
flexy is offline   Reply With Quote
Old 08-02-2006, 07:45 PM   #3
astgtciv
Resu Deretsiger
 
astgtciv's Avatar
 
Join Date: Jul 2005
Location: St-Petersburg, Russia
Posts: 2,329
Default

Ah, perhaps the problem is that I am trying to set it programmatically by setting label.text=xxx instead of binding it...
__________________
overstream.net: add subtitles to online videos (youtube, vimeo, blip.tv...).
astgtciv is offline   Reply With Quote
Old 08-02-2006, 08:03 PM   #4
flexy
Everything about me's...
 
Join Date: Aug 2006
Location: UK
Posts: 198
Default

Try:

Code:
<mx:Script>
	<![CDATA[
[Bindable] private var myText:String = "your text";
	]]>
</mx:Script>

<mx:Label text="{myText}"/>
flexy is offline   Reply With Quote
Old 08-02-2006, 08:39 PM   #5
astgtciv
Resu Deretsiger
 
astgtciv's Avatar
 
Join Date: Jul 2005
Location: St-Petersburg, Russia
Posts: 2,329
Default

Thank you, flexy. Your example definitely works. My problem wasn't the binding, though - it was that I was adding my label (via new Label(), addChild()) in a class that was extending mx.core.Container. Once I changed for that class to extend mx.containers.Canvas and added the label the same way, everything worked. I guess it's the container that is supposed to take care of the sizing of the components inside of it, and mx.core.Container simply does nothing, so I had to do it manually somehow. But mx.containers.Canvas does the sizing and layout automatically... I better go read about the component architecture in Flex. For some reason I am finding it very alien, coming from Flash...
__________________
overstream.net: add subtitles to online videos (youtube, vimeo, blip.tv...).
astgtciv is offline   Reply With Quote
Old 08-03-2006, 05:55 PM   #6
flexy
Everything about me's...
 
Join Date: Aug 2006
Location: UK
Posts: 198
Default

Ah yes, you need to extend a Container class, such as canvas, that already controls sizing and layout of children, otherwise you get the scenario you experienced. One of those things, you'll do it once, but never again!!

Good luck with the 'reading-up'; Flex documentation is sh1te at the moment!
flexy is offline   Reply With Quote
Old 08-03-2006, 06:23 PM   #7
astgtciv
Resu Deretsiger
 
astgtciv's Avatar
 
Join Date: Jul 2005
Location: St-Petersburg, Russia
Posts: 2,329
Default

Do you expect the docs to be updated for the better? This definitely hasn't been the overall trend with MM over the years

One thing I can say is that the Flex docs certainly are very thorough... all the 2000 pdf pages of them.
__________________
overstream.net: add subtitles to online videos (youtube, vimeo, blip.tv...).
astgtciv is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Controlling Dynamic Text length fahadbht ActionScript 2.0 5 02-02-2007 11:14 PM
calling a PDF file in Flash AudryLucy Projectors and CDs 20 12-30-2006 01:43 PM
Set the height and width of a dynamic text that is reciving a LoadVars?? pirulee ActionScript 2.0 1 03-21-2006 07:20 PM
XML/ActionScript help pleeeeeeese....... witchking ActionScript 2.0 3 01-21-2005 06:42 AM
cells in scrollable text window? oldspice ActionScript 1.0 (and below) 2 04-02-2002 02:59 PM


All times are GMT. The time now is 06:17 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.