The following example shows you how to position controls on the display list using the <mx:ConstraintColumns /> and <mx:ConstraintColumn /> tags.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/10/02/positioning-controls-in-flex-3-using-constraint-columns/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:ApplicationControlBar dock="true">
        <mx:Form>
            <mx:FormItem label="col1 width:">
                <mx:HSlider id="slider1"
                        minimum="50"
                        maximum="250"
                        value="200"
                        liveDragging="true"
                        snapInterval="1"
                        tickInterval="20"
                        dataTipPrecision="0" />
            </mx:FormItem>
            <mx:FormItem label="col2 width:">
                <mx:HSlider id="slider2"
                        minimum="50"
                        maximum="250"
                        value="200"
                        liveDragging="true"
                        snapInterval="1"
                        tickInterval="20"
                        dataTipPrecision="0" />
            </mx:FormItem>
        </mx:Form>
    </mx:ApplicationControlBar>

    <mx:Canvas width="100%">
        <mx:constraintColumns>
            <mx:ConstraintColumn id="col1" width="{slider1.value}" />
            <mx:ConstraintColumn id="col2" width="{slider2.value}" />
        </mx:constraintColumns>

        <mx:Button label="OK" left="col1:0" right="col1:0" />
        <mx:Button label="Cancel" left="col2:0" right="col2:0"/>
    </mx:Canvas>

</mx:Application>

View source is enabled in the following example.

For more information on enhanced constraints in Flex 3, see “Flex 3 Details – Enhanced Constraints”.

 
Tagged with:
 
About The Author

Peter deHaan

Peter deHaan currently works for Adobe on the Flex SDK QA team. While not working on Flex, Flash, and ColdFusion applications, Peter enjoys making up bios and writing in 3rd person. Peter's rarely updated blog can be found at blogs.adobe.com/pdehaan/, actionscriptexamples.com, airexamples.com, and coldfusionexamples.com.

0 Responses to Positioning controls in Flex 3 using constraint columns

  1. Ian Ilsley says:

    Great Article , however I’m having trouble with the stability of FlexBuilder3 B2 when using constraintRows/constraintColumns , have you tried adding more rows ? Once you get to
    approx 10 rows , FB3 will crash alot , the swf that is generatored runs really slowly also , eating cpu / memory .

  2. peterd says:

    Ian Ilsley,

    This is probably one of the first times I’ve played with the new constraint rows and columns in Flex Builder 3. If you have a simple, reproducable test case, would you mind filing it in the public Flex Bugbase at http://bugs.adobe.com/flex/ and somebody at Adobe can investigate. (Also, post the bug number here if you don’t mind and I can try and push it through the queue a bit faster. Thanks.)

    Peter

  3. Ian Ilsley says:

    Hi Peter ,

    I’ve already logged a bug

    http://bugs.adobe.com/jira/browse/FB-9904

    thanks

    Ian

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree