1 Reply Latest reply on Mar 7, 2010 10:13 PM by Madhav Subedi

    addEventListner question.

    SpaghettiCoder Level 3

      <mx:Button id="myButton" click="closeWindow()"/>


      Am I understanding this right, on click of a button close window function gets executed...and no argument needs to be passed in???


      When I try to do it in actionscript, I can't seem to add a event listener that just runs a function WITHOUT requiring an argument passed into it.


      myButton.addEventListener(MouseEvent.CLICK, closeWindow);  is there more to the click="closeWindow()" or is it really running a function without requiring arguments passed into it???

        • 1. Re: addEventListner question.
          Madhav Subedi Level 4

          myButton.addEventListener(MouseEvent.CLICK, closeWindow); will pass the event object as argument to the closeWindow function.

          so your function definition should be

          private function closeWindow(event:MouseEvent)


          if you want to pass the same event object through inline handler ( or use the same function from as and mxml),

          either pass the event object from mxml : <mx:Button id="myButton" click="closeWindow(event)"/>

          or make the argument optional:     private function closeWindow(event:MouseEvent=null) if you dont have to use the event object in the function.