CPruittCCB,
> var myGreeter:Greeter = new Greeter();
> mainText.text = myGreeter.sayHello("Bob");
>
> When I try & test the movie I get 2 errors:
I'm only getting one, which is "Incorrect number of
arguments. Expected
no more than 0," and the reason for that is because the
sayHello() method
isn't set up to receive any parameters. If you change your
existing ...
public function sayHello():String
... to this ...
public function sayHello(msg:String):String
... just as a for-instance, that error goes away. Have you
saved both the
FLA and the AS file? If you haven't saved your FLA yet, it
won't know where
to find your Greeter.as file (that is, the Greeter class),
which would
explain your "type not found" error.
Check Edit > Preferences, ActionScript category, and
click the
ActionScript 3.0 Settings button to make sure your classpath
setting has an
entry with nothing but a dot (.) in it. That dot means "Look
in the current
folder" when Flash needs to start hunting for external
classes. Otherwise,
you'll have to use the import statement to let Flash know
where that Greeter
class is.
Another thing to consider, if you're expecting to see the
word "Bob" in
the text field, is that you're not currently passing the
incoming parameter
back out of the method (because there is no incoming
parameter). Something
like this would do it:
package {
public class Greeter {
public function sayHello(msg:String):String {
var greeting:String;
greeting = "Hello, " + msg;
return greeting;
}
}
}
David Stiller
Co-author, Foundation Flash CS3 for Designers
http://tinyurl.com/2k29mj
"Luck is the residue of good design."