This content has been marked as final. Show 4 replies
I Forgot to add the code of the component .as for a better understanding of my problem. Here it is :
public class ImageComponent extends Panel
private var wImage:Image;
public function ImageComponent(name:String, type:String, item:Object)
wImage = new Image();
wImage.id = item.UniqueName;
wImage.load("D:/" + item.Type + ".jpg");
this.title = item.Name;
this.doubleClickEnabled = true;
this.data = item;
Flex uses a multi-phase approach to creating components. In order to see a component on the screen, Flex has to measure it, position it, and render it. That's done in several passes. That means you cannot create a component, set its properties and expect to get its width - that won't be determined until "later".
To work properly you need to go with the flow of the Flex framework. It is easier than it sounds. First, no matter what component you have your code within, as long as it is a class that extends UIComponent (and MXML files for the most part do), you can use the Flex framework.
First, create your components in the createChildren function:
override protected function createChildren() : void
// now create your components - just do new YourComponent() and set its properties and styles.
override protected function commitProperties() : void
// now use any of the properties in this file to modify your components. For example, may be you have a property in this
// file which changes a property on the components created in createChildren(). You have to do this here because
// your property in this file may not be set when createChildren is called.
override protected function measure() : void
// The Flex framework calls this function when it wants to know how big your component is. If you have set your component's
// width and height explicitly, this function won't be called. If it is called, set measuredWidth and measuredHeight to reasonable
override protected function updateDisplayList( unscaledWidth, unscaledHeight ) : void
super.updateDisplayList( unscaledWidth, unscaledHeight );
// When this function is called your components have been measured so they will now have a width and height
// so you can position them. Or you can change their width and height if need to.
Take a moment and read up on these functions in the Flex documentation, it will make writing your own components a lot easier.
can you please point me to a doc or tutorial describing this process?
"vikceo" <firstname.lastname@example.org> wrote in message
> can you please point me to a doc or tutorial describing this process?
There's an example available from the Start Page.