I have a custom layout called as NewsLayout:
override public function updateDisplayList(width:Number, height:Number)
: void
{
super.updateDisplayList( width, height );
var layoutTarget:GroupBase = target;
var element:ILayoutElement;
for( var i:int = 0; i < layoutTarget.numElements; i++ )
{
element = layoutTarget.getElementAt( i );
if(i==0){
element.setLayoutBoundsSize( NaN, NaN );
element.setLayoutBoundsPosition( 0, 0 );
}
else if(i==1)
{
var refEl = layoutTarget.getElementAt( 0 );
element.setLayoutBoundsSize( NaN, NaN );
element.setLayoutBoundsPosition( 0, refEl.height+5);
}
else if(i==2)
{
var refEl = layoutTarget.getElementAt( 0 );
var refEl2 = layoutTarget.getElementAt( 1 );
element.setLayoutBoundsSize( NaN, NaN );
element.setLayoutBoundsPosition( Math.max(refEl2.width,refEl.width)+5, 0);
}
}
}
And my custom component uses this layout and three more. Its layout may change on fly . Whichever layout it uses, my component should wrap all the elements inside it.
For this I tried to override the measure method to resize the component according to components inside it. I am trying to calculate the bottom point of all items inside it like this. Unexpectedly y position of all elements is 0, but as you can see, I am setting the coordinates of them in layout class.
override protected function measure():void {
super.measure(); var max= 0;
for(var i=0 ; i < this.numElements;i++)
{
if((this.getElementAt(i).height +this.getElementAt(i).y) > max)
max = this.getElementAt(i).height + this.getElementAt(i).y;// here y position is 0
}
//this.height =this.measuredHeight;
this.measuredHeight = max;
this.height = max;
trace("maxheight:"+max);
What is the correct way to let the component wrap all the elements inside it, regardless the layout it uses?
In flex component lifecycle measure() call once and before updateDisplayList(); So your components has y position as 0; Try to use setActualSize(width, height) for all elements in updateDisplayList().