EnterCDKeyScreen.as 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import flash.external.*;
  2. import gfx.controls.TextInput;
  3. import gfx.controls.Button;
  4. class Screens.EnterCDKeyScreen extends Screen
  5. {
  6. private var enterCdKeyOKButton:Button;
  7. private var cancelButton:Button;
  8. private var cdKeyEditBox:TextInput;
  9. private var tfFailedMsg:TextField;
  10. public function EnterCDKeyScreen()
  11. {
  12. ConsoleWindow.Trace("Constructing EnterCDKeyScreen");
  13. mScreenId = ScreenID.ENTER_CD_KEY;
  14. mScreenTabId = ScreenTab.ID_CD_KEY;
  15. tfFailedMsg._visible = false;
  16. }
  17. public function VOnFinishedLoading():Void
  18. {
  19. //Add click event for buttons
  20. enterCdKeyOKButton.addEventListener("click", this, "f2c_CheckCDKey");
  21. cancelButton.addEventListener("click", this, "Cancel");
  22. //Add callbacks for C++
  23. ExternalInterface.addCallback("c2f_CheckCDKeyResult", this, c2f_CheckCDKeyResult);
  24. super.VOnFinishedLoading();
  25. }
  26. public function f2c_CheckCDKey():Void
  27. {
  28. tfFailedMsg._visible = false;
  29. ConsoleWindow.Trace("cdKeyEditBox.text = " + cdKeyEditBox.text);
  30. ExternalInterface.call("f2c_CheckCDKey", cdKeyEditBox.text);
  31. }
  32. public function Cancel():Void
  33. {
  34. ConsoleWindow.Trace("EnterCDKeyScreen calling login screen");
  35. LobbyInterface.Instance.ShowScreen( ScreenID.LOGIN );
  36. }
  37. public function c2f_CheckCDKeyResult(reasonIdentifier:String, userUsedBy:String, activationDate:String, wasStolen:Boolean, usable:Boolean):Void
  38. {
  39. switch (reasonIdentifier)
  40. {
  41. case "SUCCESS":
  42. if (usable==true)
  43. {
  44. // if usable==true, we're ok
  45. ConsoleWindow.Trace("RegisterAccount?");
  46. //_root.gotoAndPlay("RegisterAccount");
  47. LobbyInterface.Instance.ShowScreen( ScreenID.REGISTER_ACCOUNT_PERSONAL );
  48. }
  49. else if (wasStolen==true)
  50. {
  51. ConsoleWindow.Trace("account stolen?");
  52. // If wasStolen==true, this cd key was stolen. Display appropriate error message and ask user to reenter
  53. }
  54. else
  55. {
  56. ConsoleWindow.Trace("cd key already in used");
  57. // CD key already used. Display appropriate error message and ask user to reenter
  58. }
  59. break;
  60. case "CDKey_GetStatus_TITLE_NOT_IN_USE":
  61. // Internal error, just display bad title
  62. break;
  63. case "CDKey_GetStatus_UNKNOWN_CD_KEY":
  64. tfFailedMsg.text = "Unknown CD KEY";
  65. //tfFailedMsg._visible = true;
  66. // Most common case, CD key was mistyped. Display appropriate error message and ask user to reenter
  67. break;
  68. case "REQUIRED_TEXT_IS_EMPTY":
  69. tfFailedMsg.text = "PLEASE ENTER CD KEY";
  70. //tfFailedMsg._visible = true;
  71. // Field was blank
  72. break;
  73. }
  74. if ( reasonIdentifier != "SUCCESS" )
  75. {
  76. LobbyInterface.Instance.CreateMessageBox( reasonIdentifier );
  77. }
  78. }
  79. }
粤ICP备19079148号