2 Replies Latest reply on Feb 20, 2007 4:51 AM by itsthetaste

    Accordion Change Event

    itsthetaste
      Hi everybody, Ive got a question.

      I am trying to use an accordion like shown below. I would like to be able to click on the second pane and keep open the first based upon some custom logic. If left the custom logic out as the example does not need it.

      The problem is that if I click the pane labeled "one" the change event fires but the accordion does not change back to "zero". Is there a problem with my logic? Has the event already fired?

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
      <mx:Script>
      <![CDATA[
      import mx.events.IndexChangedEvent;

      private function accChange(e:IndexChangedEvent) : void {
      // some custom logic here
      // if (models.lengh == 0)
      myAcc.selectedIndex = 0;
      }
      ]]>
      </mx:Script>
      <mx:VBox>
      <mx:Accordion id="myAcc" height="100" width="100" change="accChange(event)">
      <mx:Box label="zero"/>
      <mx:Box label="one"/>
      <mx:Box label="two"/>
      </mx:Accordion>
      <mx:Label text="{myAcc.selectedIndex}"/>
      </mx:VBox>
      </mx:Application>

      Thanks in advance for any help.
        • 1. Re: Accordion Change Event
          ntsiii Level 3
          I can get you partway there. The code below will change the accordion to the selected index, but it switches to the clicked view first.

          Tracy


          private function accChange(e:IndexChangedEvent) : void {
          callLater(navAcc);
          }

          private function navAcc():void
          {
          // some custom logic here
          // if (models.lengh == 0)
          myAcc.selectedIndex = 0;
          }//
          • 2. Re: Accordion Change Event
            itsthetaste Level 1
            Thanks for the reply Tracy.

            I didn't know about the callLater method so thank for that. I got it to do the same thing as you by placing an Alert in the change event which calls another method upon clicking the button.

            private function accChange(e:IndexChangedEvent) : void {
            // some custom logic here
            if (models.lengh == 0)
            Alert.show("Please select at least 1 Model","",4.0,this,showZero);
            }

            private function showZero(event:CloseEvent):void {
            myAcc.selectedIndex = 0;
            }

            But it would be nice to cancel the change before it happens.
            Anyway, thanks for looking.