6 Replies Latest reply: Aug 19, 2012 8:21 AM by Andrei1 RSS

    Please check my code for calling 8 functions sequentially with one button

    TimsterVideo

      Does this code look good for calling functions Func1  thru  Func8 every time  next_btn is clicked?

       

      I get the following error:    Argument count mismatch on FWA_fla::MainTimeline/nextReg(). Expected 0, got 1.

       

      My research tells me its most likely bad syntax. Do I need "Private" function? Thanks so much, I'm lost !!!

       

      var counter:Number = 0;

       

      this.next1_btn.addEventListener (MouseEvent.CLICK, nextFunc);

       

      function nextFunc(event:MouseEvent) : void

      {

          if (counter == 9) {

                                      (counter == 0);

                      }

                      counter++;

                      trace(counter)

          this["Func"+counter]();

      }

       

       

      //reg1 thru reg8 are defined below

      function Func1 (event:MouseEvent) : void

      {

      do some thing

      }

       

      function Func1 (event:MouseEvent) : void

      {

      do some thing

      }

       

      // etc.

        • 1. Re: Please check my code for calling 8 functions sequentially with one button
          Ned Murphy MVP

          No the code you show will not work.  You cannot have functions with the same name. Also, the errror is indicating a problem with a function named nextReg.  You do not show any function by that name.  If you are programming in the timeline you do not want to use private/public/etc...

          • 2. Re: Please check my code for calling 8 functions sequentially with one button
            TimsterVideo

            So sorry, I edited the code once I posted it to make more sense but I edited it poorly.  lets try again:

             

             

            Does this code look good for calling functions Func1  thru  Func8 every time  next_btn is clicked?

             

            I get the following error:    Argument count mismatch on FWA_fla::MainTimeline/nextFunc(). Expected 0, got 1.

             

            My research tells me its most likely bad syntax. Do I need "Private" function? Thanks so much, I'm lost !!!

             

            var counter:Number = 0;

             

            this.next1_btn.addEventListener (MouseEvent.CLICK, nextFunc);

             

            function nextFunc(event:MouseEvent) : void

            {

                if (counter == 9) {

                    (counter == 0);

                            }

                            counter++;

                            trace(counter)

                this["Func"+counter]();

            }

             

             

            //Func1 thru Func8 are defined below

            function Func1 (event:MouseEvent) : void

            {

            do some thing

            }

             

            function Func2 (event:MouseEvent) : void

            {

            do some thing

            }

             

            // etc. thru Func8

            • 3. Re: Please check my code for calling 8 functions sequentially with one button
              TimsterVideo

              So sorry, I edited the code once I posted it to make more sense but I edited it poorly.  lets try again:

               

               

              Does this code look good for calling functions Func1  thru  Func8 every time  next_btn is clicked?

               

              I get the following error:    Argument count mismatch on FWA_fla::MainTimeline/nextFunc(). Expected 0, got 1.

               

              My research tells me its most likely bad syntax. Do I need "Private" function? Thanks so much, I'm lost !!!

               

              var counter:Number = 0;

               

              this.next1_btn.addEventListener (MouseEvent.CLICK, nextFunc);

               

              function nextFunc(event:MouseEvent) : void

              {

                  if (counter == 9) {

                      (counter == 0);

                              }

                              counter++;

                              trace(counter)

                  this["Func"+counter]();

              }

               

               

              //Func1 thru Func8 are defined below

              function Func1 (event:MouseEvent) : void

              {

              do some thing

              }

               

              function Func2 (event:MouseEvent) : void

              {

              do some thing

              }

               

              // etc. thru Func8

              • 4. Re: Please check my code for calling 8 functions sequentially with one button
                Ned Murphy MVP

                Seeing as how you seem to be unable to show actual code/error messages, the best I can offer is... the errror is indicating that you do not specify the argument that you show in the code you posted for the nextFunc function

                 

                Your other functions you show having an argument but you do not send one to them.

                 

                function nextFunc(event:MouseEvent) : void // this line requires the "event.MouseEvent"

                 

                function Func1 (event:MouseEvent) : void // these lines should not have "event.MouseEvent"

                • 5. Re: Please check my code for calling 8 functions sequentially with one button
                  TimsterVideo

                  You were exactly right. My next problem is that I can't seem to reset the countReg var back to 0 once it hits 8. any ideas?

                   

                   

                  var countReg:Number = 0;

                   

                   

                  function nextReg(event:MouseEvent) : void

                  {

                               if (countReg == 9)

                            {

                                      (countReg == 0);

                                      }

                            countReg++;

                   

                            trace (countReg)  // it just keeps counting up. won't start over after 8

                   

                  }

                   

                   

                  this.next1_btn.addEventListener (MouseEvent.CLICK, nextReg);

                  • 6. Re: Please check my code for calling 8 functions sequentially with one button
                    Andrei1 Community Member

                    This should work:

                     

                     

                    next1_btn.addEventListener(MouseEvent.CLICK, nextFunc);
                     
                    var counter:int = 0;
                     
                    function nextFunc(e:MouseEvent):void
                    {
                           this["func" + counter % 9]();
                          counter++;
                    }
                     
                    function func1():void
                    {
                          trace("func 1 called");
                    }
                     
                    function func2():void
                    {
                          trace("func 2 called");
                    }
                    // etc...