我需要我的脚本停止并等待,直到按下“输入”键,然后继续,如果不满足要求,则返回并再次等待。
它是我正在开发的游戏的登录屏幕,它需要等待用户按 Enter,然后检查提供的凭据并允许/拒绝它们。
//log-in screen
loginframe = new Login_Frame();
addChild(loginframe);
LoginToServer();
function LoginToServer():Boolean
{
inputname = new TextField;
inputname.type = TextFieldType.INPUT;
inputname.border = true;
inputname.x = 200;
inputname.y = 200;
inputname.height = 35;
inputname.width = 545;
inputname.multiline = false;
inputname.text = "example";
loginframe.addChild(inputname);
inputpass = new TextField;
inputpass.type = TextFieldType.INPUT;
inputpass.border = true;
inputpass.x = 200;
inputpass.y = 300;
inputpass.height = 35;
inputpass.width = 545;
inputpass.multiline = false;
inputpass.text = "example";
loginframe.addChild(inputpass);
loginframe.addEventListener(KeyboardEvent.KEY_UP, hwndLogKeyboard);
while (!loginsucsess)
{
//do nothing *this halts the compiler, takes 30+ seconds for window to appear after execution*
//and causes the debugger to shut off (due to delay fault)
//so i have three problems
//1. this is clearly not an accepable way to do this
//2. this code dosnt work, without my debugger i cant fix it
//3. even if the code did work, this is a huge project, i cant be goin without my debugger
}
return true;
}
function hwndLogKeyboard(evt:KeyboardEvent):void
{
if (evt.keyCode == 13)
{
if ((inputname.text == "tyler") && (inputpass.text == "shadowcopy"))
loginsucsess = true;
}
}
我来自 C++ 背景,这个解决方案可以很好地工作,但 flash 似乎在旋转拇指时遇到了问题。
当然,我尝试询问 Google,但搜索结果甚至没有接近所需主题(我:AS3 等待按键 - Google:学习 Flash OOP!)<--不,糟糕的 Google。
提前谢谢;泰勒