Select to view content in your preferred language

vertically align swatch and label in Hbox

1308
6
10-18-2010 08:03 AM
PeteVitt
Frequent Contributor
Hi - I'm trying to verically align a swatch and a label in an hbox by setting the verticalcenter of the swatch and then setting the vertical center of the label to the same value -- not working.  Any ideas on why or a better approach I could take?  below is code

Thanks

Pete

......
var sr:SimpleRenderer=SimpleRenderer(aRenderer);
swatch=sr.symbol.createSwatch(50, 50);
swatch.verticalCenter=25;
aLabel.verticalCenter=swatch.verticalCenter;
.....

hBox.addChild(swatch);
hBox.addChild(aLabel);
Tags (2)
0 Kudos
6 Replies
RobertScheitlin__GISP
MVP Emeritus
Pete,

  Just set the vertical align of the hbox.
0 Kudos
PeteVitt
Frequent Contributor
Pete,

  Just set the vertical align of the hbox.


Robert - the verticalAlign property is not recognized in my intellisense.  When I try to use it I get an Error: Access of possibly undefined property verticalAlign through a reference with a static type mx:containers:hbox
0 Kudos
Drew
by
Frequent Contributor
Pvitt,

You can set the vertical align programatically using the below code.


myHBox.setStyle("verticalAlign","middle");



You can learn more about setStyle() here
http://livedocs.adobe.com/flex/3/html/help.html?content=styles_08.html

Drew
0 Kudos
PeteVitt
Frequent Contributor
Thanks

Complies and runs but has no effect on the alignment -- I think it has something to do with the swatch -- if I add two labels they align vertically just fine
0 Kudos
PeteVitt
Frequent Contributor
I shrunk the height of the swatch down to the hieght of the label -- not the best, but they do line up now -- fortunately all my legend items are points
0 Kudos
DanJensen
Deactivated User
Your only other option may be to use a group instead of an HBox, then specify the x, y.  Using Group you could retain your original swatch size.  Since you know the height difference between the swatch and the label you should be able to center them.
0 Kudos