import mx.controls.MenuBar;
class MyMenuBar extends MenuBar
{
function measure():Void
{
super.measure();
var item = getMenuAt(0);
var myTF = _getTextFormat();
var txt = item.text;
var textExt = myTF.getTextExtent2(txt);
var textH = textExt.height;
preferredHeight = textH;
}
}
I had to modify a couple of things from your example. First the _measurePreferredHeight property doesn't seem seem to exist for the MenuBar. I just used preferredHeight property. Additionally, I couldn't find any way to iterate through the menus in the menu bar. Maybe I'm missing something, but I read through the API docs on the MenuBar pretty thoroughly. What I wrote seems to work. It assumes there's at least one menu item and bases the size off of that item. I my case its still making the menu item a little short since the first item doesn't have any letters that reach below the fonts baseline.
So my question now is... Is there a way to iterate through the menus in a menubar? Oh, I also found this bit of info in the docs:
---
measure
measure(
)
:
Void
The MenuBar assumes a default height of 550x22. It does not measure its contents to determine its size.
---
Seems a like a bit of an oversight to me, but at least it is documented.
-- Matthew
On 4/19/05, Matthew Shirey <[EMAIL PROTECTED]> wrote:
Thank you, that did make it more clear. I knew what you meant by extending the class, but I wasn't quite sure about overriding the measure method. I didn't know if I would need to call the base measure method or where. This cleared it up, thanks,
M.On 4/19/05, Manish Jethani < [EMAIL PROTECTED]> wrote:
On 4/20/05, Matthew Shirey <[EMAIL PROTECTED]> wrote:
> I think I know what you mean, I'll give it a shot. Thank you,
In case I was not clear, by "extend" I meant really subclass the
component class in ActionScript and override the measure function:
class MyMenuBar extends MenuBar
{
function measure():Void
{
super.measure();
// set _measuredPreferredHeight here to the right value
}
}
And use it in your MXML code as usual:
<MyMenuBar>
...
</MyMenuBar>
--
[EMAIL PROTECTED]
http://manish.revise.org/
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
Yahoo! Groups Links
- To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.

