1 Reply Latest reply on Aug 26, 2009 4:56 PM by wolfman33

    Custom Components and passing arguments

    Marlene Level 1

      This afternoon i got a great answer regarding the use of custom MXML components and calling a function back in the main application file. I can accomplish this now by using parentDocument BUT I need to pass the name of a function(for filtering) as a parameter of the function call in the custom component. Below are the two code fragments.

       

      Custom Component Code

       

      <mx:LinkButton label="10% off or more" click="parentDocument.filterFunction(showTenPercent)" />

       

       

      Main App Code

       

      public function filterFunction(functionName:Function):void {

      merchantDG.visible=true;

      merchantData.filterFunction=functionName;

      merchantData.refresh();

      }

       

                  public function showTenPercent(item:Object):Boolean {

                          return (item.merchantOfferCategory=="10%");

                  }        

       

       

      The filterFunction in the main App is called by multiple components so I believe I need to keep in centralized in the main app. There is probably another way to do this but I am building my Flex skills slowly and need to understand how to do this. As the code is now, I get an error about functions and strings.

        • 1. Re: Custom Components and passing arguments
          wolfman33

          I believe instead of calling the function from inside the custom component you need to do this from inside your main application whenever you're initiating the custom component.

           

          for ex.

           

          <custom:LinkBtnCustom label="10% off or more"  click="filterFunction(showTenPercent)"/>

           

           

          this way you don't need the parentDocument prefix.