2 Replies Latest reply on Sep 17, 2010 6:42 AM by Anton Pierhagen

    Dynamic parameters in addEventListener method

    Anton Pierhagen

      Hi all,


      I've got an question. I would like to make dynamic parameters for the method addEventListener. Like the example below


      var temp:String = "class.method";
      schermObject.addEventListener(MouseEvent.CLICK, temp);
      But this do not work.
      It needs a function Object. But i hadn't figure out how to make a dynamic function object with the
      correct method in it.
      Does anybody knows how to pull this off?
      kind regards,
      Anton Pierhagen

        • 1. Re: Dynamic parameters in addEventListener method
          BhaskerChari Level 4

          Hi Anton Pierhagen,


          There is no direct way for doing this , but there is nice work aorund for this as shown below:


          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()">
            private function init():void
             var temp:String = "class.method";
             schermObjectBtn.addEventListener(MouseEvent.CLICK, function (event:MouseEvent):void{
            private function callAnotherFunction(event:MouseEvent, temp:String):void
          <mx:Button id="schermObjectBtn" label="Click ME"/>


          If this post answers your question or helps, please kindly mark it as such.


          Bhasker Chari

          1 person found this helpful
          • 2. Re: Dynamic parameters in addEventListener method
            Anton Pierhagen Level 1

            And how do you call in that function the function of the temp variable?


              private function callAnotherFunction(event:MouseEvent, temp:String):void

                     temp ?