Skip to main content
August 3, 2007
Answered

Newbie can't get example "helloworld" working

  • August 3, 2007
  • 6 replies
  • 521 views
Hi, I'm trying top get to grips with actionscript. After following the example helloWorld (cut and paste the code from the help file) I'm getting a compiler error message .
1137: Incorrect number of arguments. Expected no more than 0. mainText.text = myGreeter.sayHello("Bob");

Can anyone help a newbie please?

This topic has been closed for replies.
Correct answer SymTsb
Your sayHello function doesn't accept arguments..... you are sending it "bob" when you are calling it.... if you want it to accept a string and have it spit out that text, you need to modify the function..

public function sayHello( var greeting:String ) : String {
return greeting;
}

then your text will set in the fla document

6 replies

kglad
Community Expert
Community Expert
August 3, 2007
you're welcome.
August 3, 2007
Thanks KGlad, that did it, now perhaps you could get adobe to fix their code!
Thanks for your help, my learning can now continue.
August 3, 2007
Thanks SymTsb,
I gave that a go but got two error message this time as follows:

1084: Syntax error: expecting identifier before var.
1084: Syntax error: expecting rightparen before leftbrace.

I have a feeling that perhaps I need to change some setup options or preferences, or perhaps there is a library or something missing from my installation. ARe there any preferences I should set?

Perhaps someone would be so good as to run the code as set out in my second post above on their computer to see if it runs correctly and let me know how it went, it would be much appreciated if someone could do this.
Sorry I can't hang around, but it's time to hit the sack. Thanks to everyone who has helped.
kglad
Community Expert
Community Expert
August 3, 2007
use:

SymTsbCorrect answer
Inspiring
August 3, 2007
Your sayHello function doesn't accept arguments..... you are sending it "bob" when you are calling it.... if you want it to accept a string and have it spit out that text, you need to modify the function..

public function sayHello( var greeting:String ) : String {
return greeting;
}

then your text will set in the fla document
August 3, 2007
Thanks a lot for your reply, I'm out for a few hours, but here is the code before I leave. Hope it make sense, I just followed the help file (Adobe Flash CS3
Proffesional) Example: Creating a basic application


Greeter.sa contents

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

and helloworld.fla script content

var myGreeter:Greeter = new Greeter();
mainText.text = myGreeter.sayHello("bob")


Helloworld.fla also has the dynamic text box with instance name of mainText as required by the help file.




kglad
Community Expert
Community Expert
August 3, 2007
show your sayHello method in the myGreeter class.