4 Replies Latest reply on Feb 13, 2011 11:06 AM by Shongrunden

    Simple Layout Question

    mr_payne

      Hi Gang,

       

      [Bindable]

      var theLayout:string = "Horizontal"; 

       

       

      <fx:Declarations>

       

       

       

           <s:BasicLayout id="Single"/>

           <s:HorizontalLayout id="Horizontal" gap="5" variableColumnWidth="true"/>

           <s:VerticalLayout id="Verticle" gap="5" variableRowHeight="true"/>

           <s:TileLayout id="Tiled"/>

       

      </fx:Declarations>

       

       

       

      how to I pass "theLayout" value into my DataGroup

       

       

      <s:DataGroup  id="ProductsDataGroup" layout = {theLayout} ...??

       

       

       

      </s:DataGroup>

        • 1. Re: Simple Layout Question
          Flex harUI Adobe Employee

          You can't pass a string.

           

          var theLayout:LayoutBase = new HorizontalLayout;  

          • 2. Re: Simple Layout Question
            Andrei Kouzmenkov

            In Spark what you need to pass is an instance of one of Layout objects, not a string.

             

            For examples see Adobe doc, e.g.:

            http://help.adobe.com/en_US/flex/using/WS0141D24B-6AEB-4721-BA04-9BF15F86350F.html

            • 3. Re: Simple Layout Question
              mr_payne Level 1

              Thanks gang..!

               

              So is it possible to change the layout on the fly...

               

              my original attempt is to make

               

              [bindale]

              public var someLayout = "Horizontal";

               

               

               

              and then go

               

               

              someLayout = "Tiled";

               

              or

               

               

              someLayout = "Verticle";

              • 4. Re: Simple Layout Question
                Shongrunden Adobe Employee

                As mentioned earlier you have to work with objects not strings.   Here is an example of what I believe is what you are trying to do:

                 

                <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

                               xmlns:s="library://ns.adobe.com/flex/spark">

                 

                    <fx:Script>

                        <![CDATA[

                            import spark.layouts.supportClasses.LayoutBase;

                 

                            [Bindable] private var someLayout:LayoutBase;

                        ]]>

                    </fx:Script>

                    <fx:Declarations>

                        <s:HorizontalLayout id="horizontalLayout" />

                        <s:VerticalLayout id="verticalLayout" />

                        <s:TileLayout id="tileLayout" />

                    </fx:Declarations>

                 

                    <s:controlBarContent>

                        <s:Button label="change layout to horizontal" click="someLayout = horizontalLayout" />

                        <s:Button label="change layout to vertical" click="someLayout = verticalLayout" />

                    </s:controlBarContent>

                 

                    <s:DataGroup layout="{someLayout}" itemRenderer="spark.skins.spark.DefaultItemRenderer">

                        <s:dataProvider>

                            <s:ArrayList>

                                <fx:String>one</fx:String>

                                <fx:String>two</fx:String>

                                <fx:String>three</fx:String>

                            </s:ArrayList>

                        </s:dataProvider>

                    </s:DataGroup>

                 

                </s:Application>