pseudopeach
pseudopeach

Reputation: 1475

Where to put layout code

I need some code to run in a component after all the sizes of its children are known. The component has an absolute layout. I thought my component's measure() function would get called after all it's children's measure() functions had been called, but it seems like since it has an absolute layout, it never even calls measure.

Anyways, it's a Canvas and my override protected function measure():void never runs. What am I doing wrong?

Upvotes: 0

Views: 107

Answers (2)

Amy Blankenship
Amy Blankenship

Reputation: 6961

updateDisplayList() is called in UIComponent's commitProperties. I believe this is called after the child sizes are known, and it is where you are supposed to put your layout code.

measure() is not called when you explicitly set a width and height on your components. If you have an absolute layout on your Canvas, but do not set a width and height, measure() will be called.

HTH;

Amy

Upvotes: 1

Exort
Exort

Reputation: 1075

You don't need to override anything, simply add a listener to the creationComplete of your component. This event is "Dispatched when the component has finished its construction, property processing, measuring, layout, and drawing."

Example where the component inherits from s:Group

<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
     xmlns:s="library://ns.adobe.com/flex/spark" 
     xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300"
     creationComplete="group1_creationCompleteHandler(event)">
<fx:Script>
    <![CDATA[
        import mx.events.FlexEvent;

        protected function group1_creationCompleteHandler(event:FlexEvent):void
        {
            //TODO add code here
        }

    ]]>
</fx:Script>
</s:Group>

Upvotes: 0

Related Questions