1137: Incorrect number of arguments. Expected no more than 0. statement copied from tutorial but not working

StackOverflow https://stackoverflow.com/questions/18963298

  •  29-06-2022
  •  | 
  •  

Question

I was following an adobe tutorial in which we make a text field and the text i update in it is from function sayHello()

import flash.display.MovieClip
import flash.display.MovieClip; 
import flash.display.Sprite;
import flash.display.SimpleButton;
import flash.events.MouseEvent;
import flash.events.TextEvent;
import flash.text.TextField;
    var myGreeter:Greeter = new Greeter();
    mainText.text = myGreeter.sayHello("Bob");

This is written in first frame^^^^^

SayHello function is in the other actionscript file in same folder with the following code

package
{
    import flash.display.MovieClip;
public class Greeter
{
public function sayHello():String
{
var greeting:String;
greeting = "Hello World!";
return greeting;
}
}
}

Maybe some would ask that did you put a TextField on the stage and give it an instance name and the answer is yes i did.

The tutorial i followed i don't know why after telling code told us correct errors if there are in it so there is a possibility that they wanted to train us maybe.

i am a little confuse with greeter class myself as why we write

sayHello("Bob")

Why not

sayHello()

i say this because the variable only has string hellow world what it has to with that man Bob

It would be kind of you if you can also explain me that,

I am asking this too becuase i also need to have complete understanding of code.

Was it helpful?

Solution

I'm not sure, but you may have conflated two steps in the tutorial. You're right that with your definition of sayHello, you should call

sayHello();

To have the function take an argument, you need to define the function to take an argument:

public function sayHello(user:String):String {
    return "Hello, " + user + "!";
}

You would then call:

sayHello('Hamza');

and it would return

"Hello, Hamza!"

OTHER TIPS

In short words: "The tutorial is wrong or it is incomplete". You call sayHello with one param but sayHello are declared without params. And the compiler give you right error for this call.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top