Amy
Amy

Reputation: 109

Flex 4: How to get actual width of a group when using 100% and top/bottom/left/right?

I have an application with width/height of 100%. I have several nested groups within and their measurements are all not set, instead being defined as top=5 or left/right=10, etc.

I'm trying to get the actual with of a group that should be 390. I've set the swf object size to be 400 from the html embed code, and the group is inside another group that is width=100%. The group has a left=5 and right=5 so the width should be 400-10. When I display the .width and .measuredWidth of this group, the width is always 400.

I'm fairly new to flex/flash. Do I need to have explicitly set widths in order to get the width of child containers? Is there something I'm doing wrong here?

Thanks!

Upvotes: 0

Views: 3548

Answers (4)

riffraff
riffraff

Reputation: 41

Percentage size of Component is calculated at parent's updateDisplayList(),so it's available only through width & height.

Methods getExplicitOrMeasuredWidth/Height() may return following:

  1. Explicit width/height

Or

  1. Measured width/height when mode is set to Wrap. This is calculated during Component's measure().

If you do not plan to override measure or updateDisplayList you simply should not use getExplicit... at all.

Upvotes: 4

Amy
Amy

Reputation: 109

It turns out there was an inner group with a path that was throwing the layout off. When I removed this element, the .width property worked as it had before.

One thing that surprised me is that .measuredWidth and getExplicitOrMeasuredWidth() both returned 10 when .width returned 390.

Upvotes: 1

eruciform
eruciform

Reputation: 7736

I believe that it's returning the right value. If you have an application A, width 400. Then you put group B inside it with width 100% and some padding. Group B really is 400, because it's extended all the way to the edges of the application. However, by giving it left/right/padding/whatever, it, in turn, can adjust its children so they aren't so close to the edges. You may need to look for the maximum width of group B's children to get what you want.

Update:

According to documentation:

http://livedocs.adobe.com/flex/3/html/help.html?content=size_position_5.html

Using constraint-based layouts overrides width and percentWidth. Try measuredWidth, though it may not be filled until the component has had time to go through its measure() phase during invalidation...

Upvotes: 0

Robusto
Robusto

Reputation: 31913

Use the getExplicitOrMeasuredWidth() method of the UIComponent. This returns the explicit width if set (e.g., width="700") or the measured width (in pixels) if not. If a percentage width is set, it returns the actual measured width.

Upvotes: 1

Related Questions