3 Replies Latest reply on Jan 13, 2010 7:24 AM by kiran_vrr

    About ArgumentError: Error #1063: Argument count mismatch



      i am newbie to Flex Environment .
      This is my first post in Flex , so please excuse if my question is a dumb one .


      I am trying to dynamically create a Button and add EventListener to it .



      public function handleClick(event:MouseEvent):void


      var myBtn2:Button = new Button()

      myBtn2.label = "Dynamic";





      public function handleClick1(event:MouseEvent):void


      Alert.show("This is for Dynamic button");                                                                                                             



      I have observered that , if i dont pass event on to the handleClick1() function i am getting ArgumentError: Error #1063: Argument count mismatch and  if i pass , all is working fine .


      Please tell me , why is it mantadatory to pass this ??





        • 1. Re: About ArgumentError: Error #1063: Argument count mismatch
          pauland Level 4

          The event listener will ALWAYS pass an event object as a parameter to the event handler so that the handler can know exactly what is responsible for generating the event and allowing you to get information about the event.


          If you have one button and one event handler then you can disregard the event parameter. If you have ten buttons we don't want to code ten different event handlers, so we have one handler and the handler is told what was responsible for triggering the event.


          Basically the event parameter tells you all about what caused the event and allows you to take action accordingly.



          • 2. Re: About ArgumentError: Error #1063: Argument count mismatch
            Gregory Lafrance Level 6

            More accurate to say that if you define an event handler in MXML, as in  <mx:Button click="clickFunc()"/> then it is optional to pass an event object with clickFunc(event), and if you do not pass it, your clickFunc() method signature does not need that argument.


            But if you add an event listener with addEventListener, then the listener method signature must always tae the event object as an argument.


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

            Greg Lafrance - Flex 2 and 3 ACE certified


            Flex / AIR Development, Training, and Support Services

            • 3. Re: About ArgumentError: Error #1063: Argument count mismatch
              kiran_vrr Level 1

              Great explanation .Thank you very much.