3 Replies Latest reply on Aug 18, 2010 6:10 PM by miguel8312

    Questions about the Accordion Component

    dimival Level 1
      I have a couple of questions about using the accordion component:

      1. When my accordion is created it shows the first child container, this child is created at this time and ifyou navigate to another child it is created as well (but only until it is first accesed). The thing in the first child i need to access properties and components that are in other children, so it marks a NULL exception, because i am trying to access properties or components that have not been created yet, but I really need to access and pass values to the other child containers at this time (without navigation to them first), so is there any way to create all the children when the accordion is created as well so i would'nt need to navigate throught its children to create them???

      2. Is it possible to deactivate the click functions of an Accordion, so the only way to change bewteen its children is programatically? I mean, you can click the buttons in the Accordion to navigate through its children but you can also do this programatically using the selectedIndex property, so i am trying to deactivate the Accordion buttons so the only way to navigate is programatically.

      Any ideas of these two questions?
        • 1. Re: Questions about the Accordion Component
          peterent Level 2
          You can use creationPolicy="all" on the Accordion and it will create all the children, not just the first one. The downside to this is that your app will take a little longer to start up. Consider this:

          Child 2:
          <mx:TextInput id="input" />

          If you trying to set child2.input = "something", a better way would be to use data binding:

          Child 2:
          [Bindable] public var inputValue:String;
          <mx:TextInput id="input" text="{inputValue}" />

          Now you can do: child2.inputValue = "something"; If the UI of child2 have not been created, setting inputValue has no ill effect; as soon as the controls on child 2 are created, data binding will assign the value. If child 2 has already been created, the data binding will also assign the value.

          You can deactivate the click event on the Accordion by intercepting it and stopping its propagation, but you have to do this in ActionScript, you cannot do this in MXML.

          myAccordion.addEventListener( "change", accHandler, true ); // true means to use capture phase

          private function accHandler( event:flash.events.Event ) : void
          {
          if( event.target is mx.containers.accordionClasses.AccordionHeader ) {
          event.stopImmediatePropagation();
          }
          }

          The idea is that you intercept the click event as it travels downward through the components (the capture phase). If the target of the event is an AccordionHeader, you stop the event from going further - that is, from reaching the AccordionHeader itself.

          You can put this event handler on the Accordion or its parent upwards to the Application.
          • 2. Questions about the Accordion Component
            dimival Level 1
            Thanks for your reply i will try to use the creationPolicy to achieve this. About the binding, i' m not really using bindings but events, for example pressing a button on child 1 will trigger an event which components in child 2 should be listening to, that's the reason why i need child 2 to be created since the beginning.

            About the propagation of the Accordion i found that there is a getHeaderAt(index:Number) method which returns the button of a child container, now once that you have this reference to the button you can deactivate it. This can help in case that you want some buttons of the accordion to be functional and some not.

            Thanks a lot for your reply
            • 3. Re: Questions about the Accordion Component
              miguel8312 Level 3

              thank thank thank you. I've been at it for two days and this simple tip of creationpolicy = "all" just made my life so much easier!!!

              AWESOME TIP!!!