0
這是一個腳本,它根據預定義的名稱列表要求並驗證用戶名稱 。從adobe adobe tutorial複製的腳本仍然不能正常工作零結果
我從教程中複製了整個腳本,但結果不算什麼,我甚至不明白爲什麼沒有錯誤!我首先通過複製腳本來學習,然後理解它,但不幸的是,結果沒有任何錯誤!我是新來編程,所以請儘量解釋的事情
腳本框架1:
var myGreeter:Greeter = new Greeter();
mainText.text = myGreeter.sayHello("")
腳本動作腳本文件命名爲招待員:
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;
}
}
}
}