2009/6/3 j2me_soul <j2me_s...@163.com>: > > > Why the label can't be displaied on the srceen?
> public class rectElement extends UIComponent > { > private var lal:Label; > public function rectElement() > { > super(); > } You don't have to write a constructor if all you're going to do it call the superclass constructor. Just so you know. You can still do it if you consider it a good practice. > override protected function createChildren():void{ > if( lal == null ){ > lal = new Label; > lal.text = "Label"; > addChild(lal); > this.explicitWidth = lal.width; > this.explicitHeight = lal.height; > } > } Normally a component should not set its own explicitWidth/explicitHeight. These properties are to be set by the Flex framework. A component should only calculate its measuredWidth and measuredHeight, based on its contents. The right place to do that is the measure() implementation. > override protected function measure():void{ > this.explicitMinWidth = this.explicitMinHeight = 50; > } > } Here you should set the meauredWidth, measuredHeight, and optionally measuredMinWidth and measuredMinHeight (they can be set to the same as measuredWidth and measuredHeight respectively). > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" > mlns:local="*"> > > <local:rectElement > > /* there is nothing on the screen. Where is the Label ? */ > </local:rectElement> > </mx:Application> Okay, you haven't implemented updateDisplayList(). That's where you have do the layout. For example, in the following way: function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void { super.updateDisplayList(unscaledWidth, unscaledHeight); lal.setActualSize(unscaledWidth, unscaledHeight); } Basically your component object is first measured by the framework, and then it is assigned a size. You have to lay out the contents of the component based on the allocated size (unscaledWidth and unscaledHeight). It is also a good idea to always call the superclass's createChildren() method at the end of your implementation. http://manishjethani.com/blog/why-the-superclasss-createchildren-should-be-called-last/ Manish