4 Replies Latest reply on May 28, 2011 11:55 AM by Shongrunden

    how can I avoid hard coding this width?

    vertex_shader

      I have something like this:

       

      <s:SkinnableDataContainer
                                    width="200"
                                    itemRenderer="MyItemRenderer"
                                    dataProvider="{ dp }">

       

       

      If I have 4 items each 50px wide, I would set the width to 200px.

      However, I want to avoid hardcoding the width.

      How can I extract the width from the item renderer?

        • 1. Re: how can I avoid hard coding this width?
          MikisMM Level 2

          What exactly are you trying to achieve? Maybe constraints (left, right, top, bottom) will do the work.

          • 2. Re: how can I avoid hard coding this width?
            milan_va

            As a quick hack, you may try

             

            <s:SkinnableDataContainer
                                          width="{50*dp.length}"
            itemRenderer="MyItemRenderer"
            dataProvider="{ dp }">

             

            but I guess that sooner or later you'll have to use ActionScript anyway as the computation gets more complicated (min+max, invisible items etc.).

             

              Milan

             

            • 3. Re: how can I avoid hard coding this width?
              vertex_shader Level 1

              Sorry, I should clarify a couple of things.

               

              1. The dp may have 50 items

              2. The SkinnableDataContainer has a Scroller for which I've disabled the thumb/track.

              3. I set the SkinnableDataContainerto display 4 of the 50 items and the user uses buttons to scroll to the next 4 items (I do the scrolling programatically with a little elastic animation)

               

              So, I'm basically setting the container to the width of the item renderer * some number of items that represent a page. For now, I think I'll do something like this:

               

              private var pageSize:int = 4;

              ...

               

              <s:SkinnableDataContainer

                              width="{ MyItemRenderer.WIDTH * pageSize }"
                              itemRenderer="MyItemRenderer"
                              dataProvider="{ dp }">

              • 4. Re: how can I avoid hard coding this width?
                Shongrunden Adobe Employee

                You might want to try not setting a width and setting requestedColumnCount on the layout instead.

                 

                <s:List>

                    <s:layout>

                        <s:HorizontalLayout requestedColumnCount="2" />

                    </s:layout>

                    <s:dataProvider>

                        <s:ArrayList>

                            <fx:String>0000</fx:String>

                            <fx:String>1000</fx:String>

                            <fx:String>2000</fx:String>

                            <fx:String>3000</fx:String>

                        </s:ArrayList>

                    </s:dataProvider>

                </s:List>