7 Replies Latest reply on Jan 15, 2009 8:58 AM by dglidden-CE

    Autosize TabNavigator to fit largest tab

    dglidden-CE Level 1
      I have a TabNavigator in which the contents do not have explicit sizes, nor does the TabNavigator itself. I want the navigator to automatically size, when the page is loaded, to fit the largest child. Does anyone know of a way to do this? My most clever attempt is the code attached, which executes on creationComplete for the TabNavigator. Unfortunately, it doesn't work.
        • 1. Re: Autosize TabNavigator to fit largest tab
          Level 7

          "CarLuva" <webforumsuser@macromedia.com> wrote in message
          news:gklisf$rae$1@forums.macromedia.com...
          >I have a TabNavigator in which the contents do not have explicit sizes, nor
          > does the TabNavigator itself. I want the navigator to automatically size,
          > when
          > the page is loaded, to fit the largest child. Does anyone know of a way
          > to do
          > this? My most clever attempt is the code attached, which executes on
          > creationComplete for the TabNavigator. Unfortunately, it doesn't work.
          >
          > nav.resizeToContent = true;
          > var maxW:int = nav.width, maxH:int = nav.height;
          >
          > for(var i=0; i < nav.numChildren; i++) {
          > var child:DisplayObject = nav.getChildAt(i);
          > nav.selectedChild = Container(child);
          > if(maxW < nav.width)
          > maxW = nav.width;
          > if(maxH < nav.height)
          > maxH = nav.height;
          > }
          >
          > nav.resizeToContent = false;
          > nav.width = maxW;
          > nav.height = maxH;
          > nav.selectedIndex = 0;

          If you set the creationPolicy on the TabNavigator to "all", then this should
          work. I don't normally recommend this, but since you really do need all of
          the children to be created when the TabNavigator is created, that's probably
          your best solution.


          • 2. Re: Autosize TabNavigator to fit largest tab
            dglidden-CE Level 1
            Setting creationPolicy to "all" was one of the first things I tried, but it doesn't seem to help.
            • 3. Re: Autosize TabNavigator to fit largest tab
              Level 7

              "CarLuva" <webforumsuser@macromedia.com> wrote in message
              news:gklkdh$t4n$1@forums.macromedia.com...
              > Setting creationPolicy to "all" was one of the first things I tried, but
              > it doesn't seem to help.

              When are you calling your function?


              • 4. Re: Autosize TabNavigator to fit largest tab
                dglidden-CE Level 1
                The TabNavigator has creationComplete="myFunc()" (where myFunc() contains the code I included above).
                • 5. Re: Autosize TabNavigator to fit largest tab
                  Level 7

                  "CarLuva" <webforumsuser@macromedia.com> wrote in message
                  news:gkln10$3am$1@forums.macromedia.com...
                  > The TabNavigator has creationComplete="myFunc()" (where myFunc() contains
                  > the code I included above).

                  Try tracing out the reported height and width of the components. It's
                  possible the components have been created but not sized. In that case,
                  you'll need to wait until the selection has actually changed (using
                  updateComplete). That will get a bit more complicated...change tab, wait
                  for updateComplete, check size in handler, change tab again, etc. So you
                  won't be able to handle it in a single function.

                  HTH;

                  Amy


                  • 6. Re: Autosize TabNavigator to fit largest tab
                    dglidden-CE Level 1
                    "It's possible the components have been created but not sized."

                    That's exactly what's happening. I should have explained that in my original post. I'll give a try to the updateComplete event handler. I hadn't realized that it was available.
                    • 7. Re: Autosize TabNavigator to fit largest tab
                      dglidden-CE Level 1
                      Got it to work with a little more tweaking. The working code is attached. The only related code in the MXML is that the TabNavigator (nav) has creationComplete="adjustNavSize(event)". If anyone has a better solution, I'd love to see it, because this is pretty messy.