Skip to main content
Participating Frequently
October 21, 2010
Answered

Arguement Error

  • October 21, 2010
  • 4 replies
  • 1306 views

Hi,

I've done a pretty simple program, but I keep getting this error message:

ArgumentError: Error #1063: Argument count mismatch on breathalyser1_fla::MainTimeline/checkDrink(). Expected 0, got 1.

I know its something simple to fix, but for the life of me I can't find where I need to make the correction!!

Here is my code:

stop();


var drink:String = "null";


beerselect_mc.alpha = 0;

wineselect_mc.alpha = 0;

alcopopselect_mc.alpha = 0;

spiritselect_mc.alpha = 0;


answer_btn.alpha = 0;


//Buttons


beer_btn.addEventListener(MouseEvent.CLICK, beerSelected);

wine_btn.addEventListener(MouseEvent.CLICK, wineSelected);

alcopop_btn.addEventListener(MouseEvent.CLICK, alcopopSelected);

spirit_btn.addEventListener(MouseEvent.CLICK, spiritSelected);


//Functions


function beerSelected (e:MouseEvent):void {

drink = "beer";

beerselect_mc.alpha = 1;

wineselect_mc.alpha = 0;

alcopopselect_mc.alpha = 0;

spiritselect_mc.alpha = 0;

answer_btn.alpha = 1;

}


function wineSelected (e:MouseEvent):void {

drink = "wine";

beerselect_mc.alpha = 0;

wineselect_mc.alpha = 1;

alcopopselect_mc.alpha = 0;

spiritselect_mc.alpha = 0;

answer_btn.alpha = 1;

}


function alcopopSelected (e:MouseEvent):void {

drink = "alcopop";

beerselect_mc.alpha = 0;

wineselect_mc.alpha = 0;

alcopopselect_mc.alpha = 1;

spiritselect_mc.alpha = 0;

answer_btn.alpha = 1;

}


function spiritSelected (e:MouseEvent):void {

drink = "spirit";

beerselect_mc.alpha = 0;

wineselect_mc.alpha = 0;

alcopopselect_mc.alpha = 0;

spiritselect_mc.alpha = 1;

answer_btn.alpha = 1;

}


//Answer button


answer_btn.addEventListener(MouseEvent.CLICK, checkDrink);



//Answer button function


function checkDrink() {

if ((drink == "beer")) {

gotoAndPlay("beeranswer");

} else if ((drink == "wine")) {

gotoAndPlay("wineanswer");

} else if ((drink == "alcopop")) {

gotoAndPlay("alcopopanswer");

} else if ((drink == "spirit")) {

gotoAndPlay("spiritanswer");

}

}

Am I being dense, and missing something really obvious?

This topic has been closed for replies.
Correct answer Andrei1-bKoviI

checkDrink() is an event handler. As such it must have one argument passed into it - MouseEvent.

So, it is supposed to be:

function checkDrink (e:MouseEvent):void{

     // the rest of the code.

}

Also, it is better to use switch...case here

4 replies

October 21, 2010

If you don't need type checking then there is no reason to specify the type.

Actually the shortest version of that code would be:

stop();
var drink:String='';

beerselect_mc.alpha=wineselect_mc.alpha=alcopopselect_mc.alpha=spiritselect_mc.alpha=answer_btn.alpha=0;

//Buttons
beer_btn.addEventListener('click', Selected);
wine_btn.addEventListener('click', Selected);
alcopop_btn.addEventListener('click', Selected);
spirit_btn.addEventListener('click', Selected);
answer_btn.addEventListener('click', Selected);
//even all the above you can eliminate and replace with a stage listener
//but to keep it simple ...

function Selected(e) {
    if (e.target!=answer_btn) {
        beerselect_mc.alpha=wineselect_mc.alpha=alcopopselect_mc.alpha=spiritselect_mc.alpha=0;
        answer_btn.alpha=1;
    }
    switch (e.target) {
        case beer_btn :
            drink="beer";
            beerselect_mc.alpha=1;
            break;
        case wine_btn :
            drink="wine";
            wineselect_mc.alpha=1;
            break;
        case alcopop_btn :
            drink="alcopop";
            alcopopselect_mc.alpha=1;
            break;
        case spirit_btn :
            drink="spirit";
            spiritselect_mc.alpha=1;
            break;
        case answer_btn :
            gotoAndPlay(drink+"answer");
            break;
    }
}

Sweet ActionScript 3

Inspiring
October 21, 2010

"If you don't need type checking then there is no reason to specify the type."

This is TOTALLY wrong from OOP perspective, and Flash optimal performance standpoints.

Object typing is not for type checking only - it has much wider implications.

Inspiring
October 21, 2010

While lunching on a sea food chowder, for those who plans to fall for the statements "data typing is not necessary" here are two reason why you should stay away from such advises and strive to ALWAYS data type your variables, functions and other objects.

This is besides widely available objective solid info on data typing.

1. Decent compiler will never allow you to write code without datatyping. Only because Flash IDE caters to wide array of developers, including novices, and is lax to not typed things, it doesn't mean that your code will be compiled anywhere else.

2. Employability. If you show a code that doesn't use data typing to someone who decides whether to have your services, in the vast majority of development groups you can count on only two possible outcomes:

a) they will not hire you (rightfully so) or

b) they will pay you only a couple of dollars more above junior janitor's salary.

Bonus: if you show non-typed code and they decided to hire you, you know they are totally unprofessional and ignorant. You can certainly use it to your advantage if you choose to.

Inspiring
October 21, 2010

Here it is with switch:

function checkDrink(e:MouseEvent):void {
     switch(drink) {
          case "beer":
               gotoAndPlay("beeranswer");
          break;
          
          case "wine":
               gotoAndPlay("wineanswer");
          break;
          
          case "alcopop":
               gotoAndPlay("alcopopanswer");
          break;
          
          case "spirit":
               gotoAndPlay("spiritanswer");
          break;
          
     }
}

October 21, 2010

That is correct, but also verbose. I pointed obviously the fact that he can place whatever argument there and he doesn't need to specify the type .. he can place as well: 'e', 'dasdsa', 'dasdsadsdf'.

P.S.

Mai lasa-ne prietene cu sfaturile tale ca am citit cateva si te faci de ras pe aici

Inspiring
October 21, 2010

"he doesn't need to specify the type"

This is an EXTREMELY bad practice not to type variables and arguments.

Andrei1-bKoviICorrect answer
Inspiring
October 21, 2010

checkDrink() is an event handler. As such it must have one argument passed into it - MouseEvent.

So, it is supposed to be:

function checkDrink (e:MouseEvent):void{

     // the rest of the code.

}

Also, it is better to use switch...case here

October 21, 2010

Dear sir you have a lot to optimize there ... your code is way to verbose and can be simplified but here is the correct version of that function:

function checkDrink(jsfgydufgdg) {

if ((drink == "beer")) {

gotoAndPlay("beeranswer");

} else if ((drink == "wine")) {

gotoAndPlay("wineanswer");

} else if ((drink == "alcopop")) {

gotoAndPlay("alcopopanswer");

} else if ((drink == "spirit")) {

gotoAndPlay("spiritanswer");

}

}

Now it's ok

Inspiring
October 21, 2010

McFlibble,

Try to use switch. Switch is much faster than multiple if/else if/else.