Calculate pixel width of custom Actionscript component
i'm still relatively new flash builder , flex, didn't think particular situation have me stumped this.
i've created custom menu.mxml component , in there i'm reading bunch of menu items out of external xml file , creating labels in actionscript in "for" loop. i've done before, in case labels need right-aligned along curve. don't want hard code x-positions, since changing simple font size throw things out. want take x value of point on curve , subtract width of label. simple enough, darn width of label returns 0. assume has label not yet having actual width straight after creating in actionscript?
i though onto overiding updatedisplaylist() , reading label width in there, still getting 0 width.
here's function draws menu (sitting inside cdata) - it's triggered creationcomplete event:
private function show():void
{
var numbuttons:int;
var menuitem:sollabel;
var mgroup:group = new group();
var xpos:array = new array(410, 468, 475, 492, 411,355, 383, 374, 328, 329, 307, 352, 385);
menuitems = new array();
numbuttons = mac.length;
(var i:uint = 0; < numbuttons; i++)
{
menuitem = new sollabel();
menuitem.text = mac.getitemat(i).name;
menuitem.setstyle("color", 0x666666);
menuitem.setstyle("fontsize", "16");
menuitem.x = xpos[i] - menuitem.width;
menuitem.y = menuspacing * i;
mgroup.addelement(menuitem);
menuitems.push(menuitem);
}
addelement(mgroup);
}
sollabel mxml label component uses default font defined in main css (so don't have embed more fonts in actionscript).
i suppose menuitem.width (in pixels) doesn't have value yet, @ point have value can position label before drawn on screen?
More discussions in Flex (Read Only)
adobe
Comments
Post a Comment