1 Reply Latest reply on Aug 2, 2008 8:04 AM by Michael Borbor

    Passing Parameters in an EventListener Function

    katychapman85
      Hey,

      I have this function:
      public function GetOptions(Menu:int):void{
      document.MenuOptions.url = " http://localhost/Flex/Personalised%20Palettes-debug/MenuOptions.php?Menu=";
      document.MenuOptions.url += Menu;
      document.MenuOptions.send();
      }

      What I'm trying to do is when a user click on a Radio button this function is called and the number of the Menu required is sent to the function.

      I've added this Event Listener to my Radio Button:

      document.RadioButtons2.addEventListener(MouseEvent.CLICK, function():void{GetOptions(2);});

      However, it's not working. Everything I've read suggests using an anonymous function in the Event Listener but for some reason it's not working.

      Any ideas?
        • 1. Re: Passing Parameters in an EventListener Function
          Michael Borbor Level 4
          Katy I recommend you to change your event listener function to be someting like this:

          public function focusInListener (e:FocusEvent):void {
          // Displays: Target of this event dispatch: [object TextField]
          trace("Target of this event dispatch: " + e.target);
          // Set the text field's background to red. Notice that, for added type
          // safety, we cast Event.target to TextField-—the actual datatype of
          // the target object.
          TextField(e.target).backgroundColor = 0xFF0000;
          }

          Remember that along the event that is sent when the event is dispatch there is a variable target that provides a reference to the object tha dispatch the event. you have to cast it to the display object it's like in the previous snipet of code it cast the e.target as a Textfield por security reasons.

          The you just add the GetOptions(int(TextField(e.target).text)) to make the call with the selected index you want.