9 Replies Latest reply on Jun 30, 2006 5:00 PM by Kwooda

    Setting default accordion selectedIndex

    Kwooda
      Is this a bug? No matter what I try, the accordion will not allow me to open/init an app with anything other than the first accordion tab open. If I set selectedIndex=1 on creationComplete, it appears open for a moment, then immediately closes (opening tab 0). Same if I set selectedIndex through the property editor in Flex Builder. How do I get around this?
        • 1. Re: Setting default accordion selectedIndex
          jtan
          Will you post some of you code? selectedIndex on Accordion seems to be working in the Beta 3 build. Here is some code that I just tried out and it is working:

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
          creationComplete="myAccord.selectedIndex=1;" >

          <mx:Accordion id="myAccord" height="200">
          <mx:VBox label="zero">
          <mx:TextInput id="ti" text="" />
          <mx:Button label="zero button" />
          </mx:VBox>
          <mx:VBox label="one">
          <mx:TextInput id="ti2" text="" />
          </mx:VBox>
          </mx:Accordion>

          </mx:Application>

          Thanks,
          Joan
          • 2. Re: Setting default accordion selectedIndex
            Kwooda Level 1
            It turns out that if I launch from Flex Builder, the accordion will open to selectedIndex for a split second, then revert back to the default state. However, if I launch my app from a URL (i.e. navigate to it directly), it opens up to selectedIndex and stays there, as desired.
            • 3. Re: Setting default accordion selectedIndex
              Level 7
              I'm not having any luck reproducing your problem. I tried the sample code
              that Joan posted, and it works fine no matter how it is launched.

              Can you post sample code that demonstrates the problem?

              --
              Mike Morearty
              Developer, Flex Builder team
              http://www.morearty.com/blog


              Kwooda wrote:
              > It turns out that if I launch from Flex Builder, the accordion will open to
              > selectedIndex for a split second, then revert back to the default state.
              > However, if I launch my app from a URL (i.e. navigate to it directly), it opens
              > up to selectedIndex and stays there, as desired.
              >
              • 4. Re: Setting default accordion selectedIndex
                Kwooda Level 1
                My problem persists, and here is the deal:

                If I create an accordion and specify a value for the SelectedIndex property, the accordion will open to that selected index when the app is launched. However, if I do not specify a value for the property, it will default to show the first tab (index 0) open.

                Now, if I do some initialization by adding something like creationComplete="initializeApp()" in the mx:Application line, and within initializeApp() I specify myAccordion.selectedIndex=1, then the problem appears. The application appears with tab 0 open, then suddenly tab 1 opens, then suddenly tab 0 opens again. It is as if some accordion initialization code is being executed twice, or is being executed AFTER my function is called (as if the creationComplete event is being handled first - and maybe it is).

                Is there some way to defer my initialization code until Flex init is complete, or to get Flex to allow my init code to override the default selectedIndex value?
                • 5. Re: Setting default accordion selectedIndex
                  ur_dtrain Level 1
                  Is you creation complete event on your accordion or on your main app? Basically any component, including the application, can have an associated creationComplete event.
                  • 6. Re: Setting default accordion selectedIndex
                    Kwooda Level 1
                    I have placed the code in the creationComplete event in either or BOTH the application and accordion control declarations and the effect is the same. The accordion opens to the desired tab for a split second, then the default tab (0) opens.
                    • 7. Re: Setting default accordion selectedIndex
                      ntsiii Level 3
                      Post a sample app.
                      Tracy
                      • 8. Re: Setting default accordion selectedIndex
                        Kwooda Level 1
                        Last week all I had to do was add creationComplete="myAcc.selectedIndex=1" to either the accordion or to the application to demonstrate the problem. Today, I cannot recreate the problem - anywhere. Even in the app where the problem has been notorious. This is bothersome as this indicates an intermittent problem. The only thing that has changed between then and now is that I allowed the windows update to take place after it has been barking at me for so long to do.
                        • 9. Re: Setting default accordion selectedIndex
                          Kwooda Level 1
                          Now, today, the problem is appearing all over the place - and on more than one computer. Apparently, it only happens the first time the app is launched - subsequent reloads opens the accordion to the proper location - something to do with the cache?

                          Currently, on my accordion, I have selectedIndex="1" in the attributes, and in the application, I have creationComplete calling a handler that sets accInfo.selectedIndex=1 in AS3. I have tried every permutation of ways to set selectedIndex to 1 and the results have never varied.