views:

1367

answers:

2

Hello!

I have some custom components, that derived from UIComponent. I overloaded the updateDisplayList so they have custom look. I've created a layouter that lays out these custom components, but to place them correctly, I have to know the custom componets width, height. They are created dynamically. After all of them created (creationCompleted event fired for every), i try to laying out them, but width/height property is still 0. I am also tried to add them to a canvas, before the layout process.

So my question is, how to create custom UIComponent that placed dynamically, and get to know the width and height of it.

thanks


edit:

With the use of the mx_internal namespace I can set width and height (using the internal $width and $height fields), and it looks like it is working. But not so clean/good solution.

A: 

Maybe this works?

component.getExplicitOrMeasuredWidth() 
component.getExplicitOrMeasuredHeight()
Arno
this returns the explicitly setted or measured width ,but both are zero.only the $width/$height fields contain something useful after creation and drawing. Can I use those fields somehow, or force the component to write their values to width/height/measuredWidth.. fields?
With the use of the mx_internal namespace I can set width and height, and it looks like it is working. But not so clean/good solution.
+1  A: 

If you're inheriting from UIComponent, rather than from one of its subclasses, you'll probably want to make sure you're implementing the measure() method, among others. Check out the Flex docs here for more information on implementing your own UIComponents -- there's a good bunch of info to read here, but it's all stuff you should probably know if you're deriving from UIComponent directly:

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

Hope it helps! You might also try posting a little code, just so we have something more specific to go on. But chances are, you're just not implementing something you should be in order to retrieve those values. (And your instinct is correct -- you shouldn't have to dig into mx_internal in order to get what you need.)

Christian Nunciato
Also might make a difference where you add the custom components. Are they being added in the createChildren method, or in the updateDisplayList method, or in MXML? But I suspect the problem is that there's no "measure" step in the children.
Glenn