3 Replies Latest reply on Feb 25, 2008 11:23 AM by ntsiii

    Is this possible?

    jefflemon Level 1
      I have a loop that kicks out a button for every record in the database:

      var buttontest:Button = new Button;
      buttontest.width = 50;
      buttontest.y = yvar;
      buttontest.x = 150;
      buttontest.addEventListener("click", handleClick2);

      And when its clicked it goes to handleClick2, is there anyway to send the yvar vairable from the loop to the click handler?
        • 1. Re: Is this possible?
          jefflemon Level 1
          in other words, something like:
          buttontest.addEventListener("click", handleClick2.send(THE VARS));

          but its the wrong syntax...
          • 2. Re: Is this possible?
            VarioPegged Level 2
            You could try using an anonymous function...

            buttontest.addEventListener("click", function(event:MouseEvent):void { handleClick2(event, yvar); })

            Then your handleClick2 function would be something like this...

            private function handleClick2(event:MouseEvent, yValue:Number): void
            //Do your stuff

            • 3. Re: Is this possible?
              ntsiii Level 3
              The handler function has access to ALL of the public members of the component that dispatched the event, via the "target" property. So do:
              private function handleClick2(event:MouseEvent): void {
              var nYVar:Number = event.target.y;

              Sometimes you need to use "currentTarget" instead of "target", depending on the dispatching component.

              Anonymous functions are somewhat inefficient.