Hi, Does naybody elese have problems with the examples in the flash docs?
I am trying to follow one of the examples in the flash docs, but I get an error that I don't understand, and was wondering if I could ask for help on this?
Greeter.as
PHP Code:
package{
public class Greeter{
/**
* Defines the names that should receive a proper greeting.
*/
public static var validNames:Array = ["Sammy", "Frank", "Dean"];
/**
* Builds a greeting string using the given name.
*/
public function sayHello(userName:String = ""):String{
var greeting:String;
if (userName == ""){
greeting = "Hello. Please type your user name, and then press the Enter key.";
}
else if (validName(userName)){
greeting = "Hello, " + userName + ".";
}
else{
greeting = "Sorry, " + userName + ", you are not on the list.";
}
return greeting;
}
/**
* Checks whether a name is in the validNames list.
*/
public static function validName(inputName:String = ""):Boolean{
if (validNames.indexOf(inputName) > -1){
return true;
}
else{
return false;
}
}
}
}
HelloWorld.fla
in one text fileds, with instance name "mainText" this is using dynamic text. Below this are text fields
one is a label(user name), the other is a input text filed with instance name textIn. In the first frame in the actions there is
PHP Code:
mainText.border = true;
textIn.border = true;
var myGreeter:Greeter = new Greeter();
mainText.text = myGreeter.sayHello("");
textIn.addEventListener(KeyboardEvent.KEY_UP, keyPressed);
function keyPressed(event:Event):void{
if (event.keyCode == Keyboard.ENTER){
mainText.text = myGreeter.sayHello(textIn.text);
}
}
The issue is with the event.keyCode, which gives me the error,"1119: Access of possibly undefined property keyCode through a reference with static type flash.events:Event.