4 Replies Latest reply on May 30, 2008 4:11 AM by Madhav Subedi

    passing argument to function

    Madhav Subedi Level 4
      obj.addEventListener(MouseEvent.MOUSE_OVER, myFunction);

      this is a line inside a loop.

      now my problem is that i need to pass an object as the argument to myFunction.

      please somebody help me.
        • 1. Re: passing argument to function
          laurent_pinson Level 1
          you can't, you will need to retrieve this object directly in myFunction (using switch, array, if...)
          • 2. Re: passing argument to function
            Madhav Subedi Level 4
            ohh god!!!!!!!!!!

            dont we have ANNNNNNNNNNNYYYYYYYYYY other easy option???????

            the object i want to pass as argument is created inside a loop..
            • 3. Re: passing argument to function
              slaingod Level 1
              You will be passed an argument: The moused over control will be you event.currentTarget. You can set whatever you want to the my_control.data, like an object { something: 'else', goes: 'here'}

              You could also use an anonymous function possibly:
              obj.addEventListener(MouseEvent.MOUSE_OVER, function(event:MouseEvent):void {
              // something custom here
              });
              (not sure if that helps or not)

              • 4. Re: passing argument to function
                Madhav Subedi Level 4
                quote:

                Originally posted by: slaingod
                You will be passed an argument: The moused over control will be you event.currentTarget. You can set whatever you want to the my_control.data, like an object { something: 'else', goes: 'here'}

                You could also use an anonymous function possibly:
                obj.addEventListener(MouseEvent.MOUSE_OVER, function(event:MouseEvent):void {
                // something custom here
                });
                (not sure if that helps or not)



                using this code, i can pass arguments to desired function,<calling my function in

                something custom here>.

                but, in my case, the argument is an object that is created inside a loop.
                so the affected object is always the last created object.

                anyway, thanks slaingold for your idea.