1 Reply Latest reply on Jun 6, 2009 6:31 AM by JeffryHouser

    Custom component : call a function from another custom component

    Celinio

      Hi,

      i call a custom component B inside another custom component A.

      That works fine.

       

      From custom component B, how can i call a function defined in custom component A ?

      Is is something like Parent.myFunction() ..?

       

       

      Thanks.

        • 1. Re: Custom component : call a function from another custom component
          JeffryHouser Level 4

          If I understand you, then an instance of Component B is embedded inside Component A, is that correct?

           

          Conceptually, a component something like this:

           

          <myNS:ComponentA>

            <msNSComponentB>

          </myNS:ComponentA>

           

          Then A has no problems calling methods /functions in Component B.  But, Component B cannot access methods / functions in Component A.

           

          The [best] way to do this is to launch an event from ComponentB; something like this:

           

          dispatchEvent(new Event('MyCustomEvent'));

           

           

          Then listen to it in Component  and perform the function:

           

          <myNS:ComponentA>

            <msNSComponentB myCustomEvent="DoStuffHere()">

          </myNS:ComponentA>

           

          If you do it this way the two components are not tightly coupled and you optimize reuse.

           

          But, in a pinch parent.myFunction() should work ( http://livedocs.adobe.com/flex/2/langref/mx/core/UIComponent.html#parent ).  Did you try that?  And what were the problems you had with it?