4 Replies Latest reply on Jul 25, 2008 12:17 PM by ntsiii

    Component Event

    afcb_chezza
      Hi,
      I'm a little confused about handeling events between components. For example, I have a sidebar 'dashboard-like' menu (which is a canvas) as a component, which when icons on it are clicked should trigger an action in the main application.

      For example, how do I attach a mouseUp event to the dashboard so that it selects the index of an accordion, which is not part of the dashboard? I can't just put mouseUp="accordion_id.selectedIndex=3" because accordion isn't within the scope of the dashboard.

      Many thanks for your help.
        • 1. Re: Component Event
          g-s-b Level 1
          There are several ways to do such, but "best practices" suggests that you use events for such communications.

          When the icon is selected, the "object" records the selection index AND triggers a [custom] "selection changed" event. In the main application, create an event handler for "selection changed" events and all a listener for it. ...simple enough.

          • 2. Component Event
            g-s-b Level 1
            There are several ways to do such, but "best practices" suggests that you use events for such communications.

            When the icon is selected, the "object" records the selection index AND triggers a [custom] "selection changed" event. In the main application, create an event handler for "selection changed" events and add a listener for it. ...simple enough.

            • 3. Re: Component Event
              ntsiii Level 3
              Yes. And why are you using MouseUp instead of a higher level event, like Click?

              Note: In your case, you will need the index clicked in the click handler. So have that data available as a public property on the components in the dashboard you are clicking. Thus, in a handler, you can do:
              private function onClickDash(event:Event):void
              var iIndex:int = event.target.indexData; // implement this property on your clickable components.

              Tracy
              • 4. Re: Component Event
                ntsiii Level 3
                Ahh, and in case you want to do this the "quick" way, you can access members lower in the component hierarchy by dotting down via their ids:

                myComp1.myCom12.myComp121.myAccordion.selectedIndex = 1;

                But go on and get used to events.

                Tracy