• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Guest
Aug 18, 2012 Aug 18, 2012

Copy link to clipboard

Copied

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.

TOPICS
ActionScript

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Aug 18, 2012 Aug 18, 2012

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"

Votes

Translate

Translate
LEGEND ,
Aug 18, 2012 Aug 18, 2012

Copy link to clipboard

Copied

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...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 18, 2012 Aug 18, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 18, 2012 Aug 18, 2012

Copy link to clipboard

Copied

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"

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 18, 2012 Aug 18, 2012

Copy link to clipboard

Copied

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);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 19, 2012 Aug 19, 2012

Copy link to clipboard

Copied

LATEST

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...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 18, 2012 Aug 18, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines