Skip to main content

Mobile Login, Register and Update User Profile Using ActionScript 3.0

Language


In this tutorial, we will teach you on how to create a Login, Register and Update User Profile Using Action Script 3.0. This project is very known in mobile applications. This application creates a Login form and a registration form for every user, each user can access and update their profile. Every data that the user fill in it will automatically save to the database.

Sample Code

Registration UI Form and Function.

  1. package views
  2. {
  3. import commons.Manager;
  4. import commons.ScreenManager;
  5. import commons.TextManager;
  6. import events.RegisterEvent;
  7. import flash.events.MouseEvent;
  8. import flash.text.TextFormatAlign;
  9. import flashx.textLayout.container.ScrollPolicy;
  10. import flashx.textLayout.formats.VerticalAlign;
  11. import models.vo.User;
  12. import mx.controls.Spacer;
  13. import mx.graphics.SolidColor;
  14. import org.osmf.layout.HorizontalAlign;
  15. import spark.components.Button;
  16. import spark.components.Group;
  17. import spark.components.Image;
  18. import spark.components.Label;
  19. import spark.components.Scroller;
  20. import spark.components.TextInput;
  21. import spark.components.VGroup;
  22. import spark.events.TextOperationEvent;
  23. import spark.primitives.Rect;
  24.  
  25. public class RegisterView extends Group
  26. {
  27. private const SCALE:Number = ScreenManager.scale;
  28. private const LABEL_FONT_SIZE:Number = 30 * SCALE;
  29.  
  30. private var usernameInput:TextInput;
  31. private var passwordInput:TextInput;
  32. private var firstnameInput:TextInput;
  33. private var middlenameInput:TextInput;
  34. private var lastnameInput:TextInput;
  35. private var messageLabel:Label;
  36. private var submitButton:Button;
  37.  
  38.  
  39. public function RegisterView()
  40. {
  41. this.percentWidth = 100;
  42. this.percentHeight = 100;
  43.  
  44. var rect:Rect = new Rect();
  45. rect.percentWidth = 100;
  46. rect.percentHeight = 100;
  47. rect.fill = new SolidColor(0x0090c2);
  48. addElement(rect);
  49.  
  50. var main:VGroup = new VGroup();
  51. main.paddingTop = 20 * SCALE;
  52. main.paddingBottom = 70 * SCALE;
  53. main.percentWidth = 100;
  54. main.percentHeight = 100;
  55. main.horizontalAlign = HorizontalAlign.CENTER;
  56.  
  57. var scroller:Scroller = new Scroller();
  58. scroller.percentWidth = 100;
  59. scroller.percentHeight = 100;
  60. scroller.viewport = main;
  61. scroller.setStyle("horizontalScrollPolicy",ScrollPolicy.OFF);
  62. addElement(scroller);
  63.  
  64. var content:VGroup = new VGroup();
  65. content.percentHeight = 100;
  66. content.horizontalAlign = HorizontalAlign.CENTER;
  67. main.addElement(content);
  68.  
  69. var logoContainer:VGroup = new VGroup();
  70. logoContainer.horizontalAlign = HorizontalAlign.CENTER;
  71. content.addElement(logoContainer);
  72.  
  73. var logo:Image = new Image();
  74. logo.source = LOGO;
  75. logo.scaleX = logo.scaleY = SCALE;
  76. logoContainer.addElement(logo);
  77.  
  78. var gap:Spacer = new Spacer();
  79. gap.height = 20 * SCALE;
  80. content.addElement(gap);
  81.  
  82. var inputContainer:VGroup = new VGroup();
  83. inputContainer.percentWidth = 100;
  84. content.addElement(inputContainer);
  85.  
  86. var accountInputContainer:VGroup = new VGroup();
  87. accountInputContainer.percentWidth = 100;
  88. inputContainer.addElement(accountInputContainer);
  89.  
  90. const INPUT_WIDTH:Number = 600 * SCALE;
  91. const SPACER_HEIGHT:Number = 10 * SCALE;
  92.  
  93. var usernameLabel:Label = new Label();
  94. usernameLabel.setStyle("fontSize", LABEL_FONT_SIZE);
  95. usernameLabel.setStyle("color", 0x000000);
  96. usernameLabel.setStyle("fontFamily", "Arial");
  97. usernameLabel.text = "Username";
  98. inputContainer.addElement(usernameLabel);
  99.  
  100. usernameInput = new TextInput();
  101. usernameInput.setStyle("fontSize", LABEL_FONT_SIZE);
  102. usernameInput.width = INPUT_WIDTH;
  103. usernameInput.addEventListener(TextOperationEvent.CHANGE, onDataChange);
  104. inputContainer.addElement(usernameInput);
  105.  
  106. var usernameSpacer:Spacer = new Spacer();
  107. usernameSpacer.height = SPACER_HEIGHT;
  108. inputContainer.addElement(usernameSpacer);
  109.  
  110. var passwordLabel:Label = new Label();
  111. passwordLabel.setStyle("fontSize", LABEL_FONT_SIZE);
  112. passwordLabel.setStyle("color", 0x000000);
  113. passwordLabel.setStyle("fontFamily", "Arial");
  114. passwordLabel.text = "Password";
  115. inputContainer.addElement(passwordLabel);
  116.  
  117. passwordInput = new TextInput();
  118. passwordInput.setStyle("fontSize", LABEL_FONT_SIZE);
  119. passwordInput.width = INPUT_WIDTH;
  120. passwordInput.displayAsPassword = true;
  121. passwordInput.addEventListener(TextOperationEvent.CHANGE, onDataChange);
  122. inputContainer.addElement(passwordInput);
  123.  
  124. var passwordSpacer:Spacer = new Spacer();
  125. passwordSpacer.height = SPACER_HEIGHT;
  126. inputContainer.addElement(passwordSpacer);
  127.  
  128. var firstnameLabel:Label = new Label();
  129. firstnameLabel.setStyle("fontSize", LABEL_FONT_SIZE);
  130. firstnameLabel.setStyle("color", 0x000000);
  131. firstnameLabel.setStyle("fontFamily", "Arial");
  132. firstnameLabel.text = "Firstname";
  133. inputContainer.addElement(firstnameLabel);
  134.  
  135. firstnameInput = new TextInput();
  136. firstnameInput.setStyle("fontSize", LABEL_FONT_SIZE);
  137. firstnameInput.width = INPUT_WIDTH;
  138. firstnameInput.addEventListener(TextOperationEvent.CHANGE, onDataChange);
  139. inputContainer.addElement(firstnameInput);
  140.  
  141. var firstnameSpacer:Spacer = new Spacer();
  142. firstnameSpacer.height = SPACER_HEIGHT;
  143. inputContainer.addElement(firstnameSpacer);
  144.  
  145. var middlenameLabel:Label = new Label();
  146. middlenameLabel.setStyle("fontSize", LABEL_FONT_SIZE);
  147. middlenameLabel.setStyle("color", 0x000000);
  148. middlenameLabel.setStyle("fontFamily", "Arial");
  149. middlenameLabel.text = "Middlename";
  150. inputContainer.addElement(middlenameLabel);
  151.  
  152. middlenameInput = new TextInput();
  153. middlenameInput.setStyle("fontSize", LABEL_FONT_SIZE);
  154. middlenameInput.width = INPUT_WIDTH;
  155. middlenameInput.addEventListener(TextOperationEvent.CHANGE, onDataChange);
  156. inputContainer.addElement(middlenameInput);
  157.  
  158. var middlenameSpacer:Spacer = new Spacer();
  159. middlenameSpacer.height = SPACER_HEIGHT;
  160. inputContainer.addElement(middlenameSpacer);
  161.  
  162. var lastnameLabel:Label = new Label();
  163. lastnameLabel.setStyle("fontSize", LABEL_FONT_SIZE);
  164. lastnameLabel.setStyle("color", 0x000000);
  165. lastnameLabel.setStyle("fontFamily", "Arial");
  166. lastnameLabel.text = "Lastname";
  167. inputContainer.addElement(lastnameLabel);
  168.  
  169. lastnameInput = new TextInput();
  170. lastnameInput.setStyle("fontSize", LABEL_FONT_SIZE);
  171. lastnameInput.width = INPUT_WIDTH;
  172. lastnameInput.addEventListener(TextOperationEvent.CHANGE, onDataChange);
  173. inputContainer.addElement(lastnameInput);
  174.  
  175. var messageContainer:VGroup = new VGroup();
  176. messageContainer.percentHeight = 100;
  177. messageContainer.width = INPUT_WIDTH;
  178. messageContainer.horizontalAlign = HorizontalAlign.CENTER;
  179. messageContainer.verticalAlign = VerticalAlign.MIDDLE;
  180. content.addElement(messageContainer);
  181.  
  182. messageLabel = new Label();
  183. messageLabel.percentWidth = 90;
  184. messageLabel.setStyle("fontSize", 28 * SCALE);
  185. messageLabel.setStyle("color", 0xFF0000);
  186. messageLabel.setStyle("textAlign", TextFormatAlign.CENTER);
  187. messageLabel.setStyle("fontFamily", "Arial");
  188. messageContainer.addElement(messageLabel);
  189.  
  190. var buttonsContainer:VGroup = new VGroup();
  191. buttonsContainer.percentWidth = 80;
  192. content.addElement(buttonsContainer);
  193.  
  194. submitButton = new Button();
  195. submitButton.setStyle("fontSize", LABEL_FONT_SIZE);
  196. submitButton.label = "Submit";
  197. submitButton.enabled = false;
  198. submitButton.percentWidth = 100;
  199. submitButton.height = 86 * SCALE;
  200. submitButton.addEventListener(MouseEvent.CLICK, onRegister);
  201. buttonsContainer.addElement(submitButton);
  202.  
  203. var buttonsSpacer:Spacer = new Spacer();
  204. buttonsSpacer.height = 20 * SCALE;
  205. buttonsContainer.addElement(buttonsSpacer);
  206.  
  207. var backButton:Button = new Button();
  208. backButton.setStyle("fontSize", LABEL_FONT_SIZE);
  209. backButton.label = "Back to Login";
  210. backButton.percentWidth = 100;
  211. backButton.height = 86 * SCALE;
  212. backButton.addEventListener(MouseEvent.CLICK, onBack);
  213. buttonsContainer.addElement(backButton);
  214. }
  215. }
  216. }

And the Function for each variable to query in the database.

  1. public function set message(value:String):void
  2. {
  3. messageLabel.text = value;
  4. }
  5.  
  6. private function onDataChange(event:TextOperationEvent):void
  7. {
  8. if (!Manager.isTextEmpty(usernameInput.text) && !Manager.isTextEmpty(passwordInput.text) && !Manager.isTextEmpty(firstnameInput.text) && !Manager.isTextEmpty(lastnameInput.text))
  9. {
  10. submitButton.enabled = true;
  11. }
  12. else
  13. {
  14. submitButton.enabled = false;
  15. }
  16. }
  17.  
  18. private function onRegister(event:MouseEvent):void
  19. {
  20. var user:User = new User();
  21. user.username = usernameInput.text;
  22. user.password = passwordInput.text;
  23. user.firstname = firstnameInput.text;
  24. user.middlename = middlenameInput.text;
  25. user.lastname = lastnameInput.text;
  26.  
  27. dispatchEvent(new RegisterEvent(RegisterEvent.PROCESS_REGISTRATION,user));
  28.  
  29. user = null;
  30. }
  31.  
  32. private function onBack(event:MouseEvent):void
  33. {
  34. dispatchEvent(new RegisterEvent(RegisterEvent.BACK_TO_LOGIN));
  35. }

Register Event For creating a string command to display if the registration successfully registered or failed.

  1. package events
  2. {
  3. import flash.events.Event;
  4.  
  5. import models.vo.User;
  6.  
  7. public class RegisterEvent extends Event
  8. {
  9. public static const PROCESS_REGISTRATION:String = 'processRegistration';
  10. public static const BACK_TO_LOGIN:String = 'backToLogin';
  11. public static const SUCCESS:String = 'success';
  12. public static const FAILED:String = 'failedRegistration';
  13.  
  14. private var _user:User;
  15. private var _message:String;
  16.  
  17. public function RegisterEvent(type:String, userObj:User=null, message:String=null)
  18. {
  19. super(type);
  20. _user = userObj;
  21. _message = message;
  22. }
  23.  
  24. public function get user():User
  25. {
  26. return _user;
  27. }
  28.  
  29. public function get message():String
  30. {
  31. return _message;
  32. }
  33.  
  34. override public function clone():Event
  35. {
  36. return new RegisterEvent(type, _user, _message);
  37. }
  38. }
  39. }

Update UI Form for updating the user profile.

  1. package views
  2. {
  3. import commons.Manager;
  4. import commons.ScreenManager;
  5.  
  6. import events.UserEvent;
  7.  
  8. import flash.events.MouseEvent;
  9. import flash.text.TextFormatAlign;
  10. import flash.text.engine.FontWeight;
  11.  
  12. import flashx.textLayout.container.ScrollPolicy;
  13. import flashx.textLayout.formats.VerticalAlign;
  14.  
  15. import models.vo.User;
  16.  
  17. import mx.controls.Spacer;
  18.  
  19. import org.osmf.layout.HorizontalAlign;
  20.  
  21. import spark.components.Button;
  22. import spark.components.HGroup;
  23. import spark.components.Label;
  24. import spark.components.Scroller;
  25. import spark.components.TextInput;
  26. import spark.components.VGroup;
  27. import spark.components.View;
  28. import spark.events.TextOperationEvent;
  29.  
  30. public class SettingsView extends View
  31. {
  32. [Embed(source="images/home.png")]
  33. private var HOME:Class;
  34.  
  35. [Embed(source="images/floppy.png")]
  36. private var SAVE:Class;
  37.  
  38. protected var mainContent:VGroup;
  39. protected const SCALE:Number = ScreenManager.scale;
  40. private const LABEL_FONT_SIZE:Number = 32 * SCALE;
  41.  
  42. private var titleLabel:Label;
  43. private var mainMenuButton:Button;
  44. private var addClass:Button;
  45.  
  46. private var usernameInput:TextInput;
  47. private var passwordInput:TextInput;
  48. private var firstnameInput:TextInput;
  49. private var middlenameInput:TextInput;
  50. private var lastnameInput:TextInput;
  51. private var messageLabel:Label;
  52. private var submitButton:Button;
  53.  
  54. private var _user:User;
  55.  
  56. public function SettingsView()
  57. {
  58. mainMenuButton = new Button();
  59. mainMenuButton.width = headerHeight;
  60. mainMenuButton.height = headerHeight;
  61. mainMenuButton.label = "Main";
  62. mainMenuButton.setStyle("fontSize", 32 * SCALE);
  63. mainMenuButton.setStyle("icon", HOME);
  64. mainMenuButton.addEventListener(MouseEvent.CLICK,onMainMenu);
  65.  
  66. navigationContent = new Array();
  67. navigationContent.push(mainMenuButton);
  68.  
  69. titleLabel = new Label();
  70. titleLabel.percentWidth = 100;
  71. titleLabel.setStyle("fontSize", 32 * SCALE);
  72. titleLabel.setStyle("color", 0xFFFFFF);
  73. titleLabel.setStyle("textAlign", TextFormatAlign.CENTER);
  74. titleLabel.setStyle("fontFamily", "Arial");
  75. titleLabel.setStyle("fontWeight", FontWeight.BOLD);
  76. titleLabel.text = "SETTINGS";
  77.  
  78. var myHGrp:HGroup = new HGroup();
  79. myHGrp.verticalAlign = VerticalAlign.MIDDLE;
  80. myHGrp.horizontalAlign = HorizontalAlign.RIGHT;
  81. myHGrp.percentWidth = 100;
  82. myHGrp.height = headerHeight;
  83. myHGrp.maxHeight = headerHeight;
  84. myHGrp.gap = 20 * SCALE;
  85. myHGrp.addElement(titleLabel);
  86.  
  87. titleContent = new Array();
  88. titleContent.push(myHGrp);
  89.  
  90. submitButton = new Button();
  91. submitButton.setStyle("fontSize", LABEL_FONT_SIZE);
  92. submitButton.setStyle("icon", SAVE);
  93. submitButton.label = "Update";
  94. submitButton.width = headerHeight;
  95. submitButton.height = headerHeight;
  96. submitButton.addEventListener(MouseEvent.CLICK, onUpdate);
  97.  
  98. actionContent = new Array();
  99. actionContent.push(submitButton);
  100.  
  101. mainContent = new VGroup();
  102. mainContent.paddingTop = 50 * SCALE;
  103. mainContent.percentWidth = 100;
  104. mainContent.percentHeight = 100;
  105. mainContent.horizontalAlign = HorizontalAlign.CENTER;
  106. mainContent.gap = 0;
  107.  
  108. var scroller:Scroller = new Scroller();
  109. scroller.percentWidth = 100;
  110. scroller.percentHeight = 100;
  111. scroller.viewport = mainContent;
  112. scroller.setStyle("horizontalScrollPolicy",ScrollPolicy.OFF);
  113. addElement(scroller);
  114.  
  115. var inputContainer:VGroup = new VGroup();
  116. inputContainer.percentWidth = 100;
  117. inputContainer.horizontalAlign = HorizontalAlign.CENTER;
  118. mainContent.addElement(inputContainer);
  119.  
  120. const INPUT_WIDTH:Number = 600 * SCALE;
  121. const SPACER_HEIGHT:Number = 10 * SCALE;
  122.  
  123. var usernameLabel:Label = new Label();
  124. usernameLabel.width = INPUT_WIDTH;
  125. usernameLabel.setStyle("fontSize", LABEL_FONT_SIZE);
  126. usernameLabel.setStyle("color", 0x000000);
  127. usernameLabel.setStyle("fontFamily", "Arial");
  128. usernameLabel.text = "Username";
  129. inputContainer.addElement(usernameLabel);
  130.  
  131. usernameInput = new TextInput();
  132. usernameInput.setStyle("fontSize", LABEL_FONT_SIZE);
  133. usernameInput.width = INPUT_WIDTH;
  134. usernameInput.addEventListener(TextOperationEvent.CHANGE, onDataChange);
  135. inputContainer.addElement(usernameInput);
  136.  
  137. var usernameSpacer:Spacer = new Spacer();
  138. usernameSpacer.height = SPACER_HEIGHT;
  139. inputContainer.addElement(usernameSpacer);
  140.  
  141. var passwordLabel:Label = new Label();
  142. passwordLabel.width = INPUT_WIDTH;
  143. passwordLabel.setStyle("fontSize", LABEL_FONT_SIZE);
  144. passwordLabel.setStyle("color", 0x000000);
  145. passwordLabel.setStyle("fontFamily", "Arial");
  146. passwordLabel.text = "Password";
  147. inputContainer.addElement(passwordLabel);
  148.  
  149. passwordInput = new TextInput();
  150. passwordInput.setStyle("fontSize", LABEL_FONT_SIZE);
  151. passwordInput.width = INPUT_WIDTH;
  152. passwordInput.displayAsPassword = true;
  153. passwordInput.addEventListener(TextOperationEvent.CHANGE, onDataChange);
  154. inputContainer.addElement(passwordInput);
  155.  
  156. var passwordSpacer:Spacer = new Spacer();
  157. passwordSpacer.height = SPACER_HEIGHT;
  158. inputContainer.addElement(passwordSpacer);
  159.  
  160. var firstnameLabel:Label = new Label();
  161. firstnameLabel.width = INPUT_WIDTH;
  162. firstnameLabel.setStyle("fontSize", LABEL_FONT_SIZE);
  163. firstnameLabel.setStyle("color", 0x000000);
  164. firstnameLabel.setStyle("fontFamily", "Arial");
  165. firstnameLabel.text = "Firstname";
  166. inputContainer.addElement(firstnameLabel);
  167.  
  168. firstnameInput = new TextInput();
  169. firstnameInput.setStyle("fontSize", LABEL_FONT_SIZE);
  170. firstnameInput.width = INPUT_WIDTH;
  171. firstnameInput.addEventListener(TextOperationEvent.CHANGE, onDataChange);
  172. inputContainer.addElement(firstnameInput);
  173.  
  174. var firstnameSpacer:Spacer = new Spacer();
  175. firstnameSpacer.height = SPACER_HEIGHT;
  176. inputContainer.addElement(firstnameSpacer);
  177.  
  178. var middlenameLabel:Label = new Label();
  179. middlenameLabel.width = INPUT_WIDTH;
  180. middlenameLabel.setStyle("fontSize", LABEL_FONT_SIZE);
  181. middlenameLabel.setStyle("color", 0x000000);
  182. middlenameLabel.setStyle("fontFamily", "Arial");
  183. middlenameLabel.text = "Middlename";
  184. inputContainer.addElement(middlenameLabel);
  185.  
  186. middlenameInput = new TextInput();
  187. middlenameInput.setStyle("fontSize", LABEL_FONT_SIZE);
  188. middlenameInput.width = INPUT_WIDTH;
  189. middlenameInput.addEventListener(TextOperationEvent.CHANGE, onDataChange);
  190. inputContainer.addElement(middlenameInput);
  191.  
  192. var middlenameSpacer:Spacer = new Spacer();
  193. middlenameSpacer.height = SPACER_HEIGHT;
  194. inputContainer.addElement(middlenameSpacer);
  195.  
  196. var lastnameLabel:Label = new Label();
  197. lastnameLabel.width = INPUT_WIDTH;
  198. lastnameLabel.setStyle("fontSize", LABEL_FONT_SIZE);
  199. lastnameLabel.setStyle("color", 0x000000);
  200. lastnameLabel.setStyle("fontFamily", "Arial");
  201. lastnameLabel.text = "Lastname";
  202. inputContainer.addElement(lastnameLabel);
  203.  
  204. lastnameInput = new TextInput();
  205. lastnameInput.setStyle("fontSize", LABEL_FONT_SIZE);
  206. lastnameInput.width = INPUT_WIDTH;
  207. lastnameInput.addEventListener(TextOperationEvent.CHANGE, onDataChange);
  208. inputContainer.addElement(lastnameInput);
  209.  
  210. var messageContainer:VGroup = new VGroup();
  211. messageContainer.paddingTop = 25 * SCALE;
  212. messageContainer.paddingBottom = 25 * SCALE;
  213. messageContainer.percentHeight = 100;
  214. messageContainer.width = INPUT_WIDTH;
  215. messageContainer.horizontalAlign = HorizontalAlign.CENTER;
  216. messageContainer.verticalAlign = VerticalAlign.MIDDLE;
  217. mainContent.addElement(messageContainer);
  218.  
  219. messageLabel = new Label();
  220. messageLabel.percentWidth = 90;
  221. messageLabel.setStyle("fontSize", 28 * SCALE);
  222. messageLabel.setStyle("color", 0xFFFFFF);
  223. messageLabel.setStyle("textAlign", TextFormatAlign.CENTER);
  224. messageLabel.setStyle("fontFamily", "Arial");
  225. messageContainer.addElement(messageLabel);
  226. }
  227. }
  228. }

And for the query function for updating the user profile form the given value.

  1. public static function get headerHeight():Number
  2. {
  3. return 120 * ScreenManager.scale;
  4. }
  5.  
  6. private function onMainMenu(event:MouseEvent):void
  7. {
  8. navigator.popToFirstView();
  9. }
  10.  
  11. public function set user(value:User):void
  12. {
  13. _user = value;
  14.  
  15. usernameInput.text = _user.username;
  16. passwordInput.text = _user.password;
  17. firstnameInput.text = _user.firstname;
  18. middlenameInput.text = _user.middlename;
  19. lastnameInput.text = _user.lastname;
  20. }
  21.  
  22. public function set message(value:String):void
  23. {
  24. messageLabel.text = value;
  25. }
  26.  
  27. private function onDataChange(event:TextOperationEvent):void
  28. {
  29. if (!Manager.isTextEmpty(usernameInput.text) && !Manager.isTextEmpty(passwordInput.text) && !Manager.isTextEmpty(firstnameInput.text) && !Manager.isTextEmpty(lastnameInput.text))
  30. {
  31. submitButton.enabled = true;
  32. }
  33. else
  34. {
  35. submitButton.enabled = false;
  36. }
  37. }
  38.  
  39. private function onUpdate(event:MouseEvent):void
  40. {
  41. var user:User = new User();
  42. user.id = _user.id;
  43. user.username = usernameInput.text;
  44. user.password = passwordInput.text;
  45. user.firstname = firstnameInput.text;
  46. user.middlename = middlenameInput.text;
  47. user.lastname = lastnameInput.text;
  48.  
  49. dispatchEvent(new UserEvent(UserEvent.PROCESS_UPDATE,user));
  50.  
  51. user = null;
  52. }

result

Login query function.

  1. public function set message(value:String):void
  2. {
  3. if(value === "Registration Successful! You can now login")
  4. {
  5. messageLabel.setStyle("color", 0xFFFFFF);
  6. }
  7. else
  8. {
  9. messageLabel.setStyle("color", 0xFF0000);
  10. }
  11.  
  12. messageLabel.text = value;
  13. }
  14.  
  15. private function checkUsernameCache():void
  16. {
  17. var loginSO:SharedObject = SharedObject.getLocal(Constants.LOGIN_SO);
  18.  
  19. if (loginSO.data.hasOwnProperty("username"))
  20. {
  21. if (!Manager.isTextEmpty(loginSO.data.username))
  22. {
  23. usernameInput.text = loginSO.data.username;
  24. return;
  25. }
  26. }
  27.  
  28. usernameInput.text = defaultUsernameText;
  29. }
  30.  
  31. private function onDataChange(event:TextOperationEvent):void
  32. {
  33. if (!Manager.isTextEmpty(usernameInput.text, defaultUsernameText) && !Manager.isTextEmpty(passwordInput.text))
  34. {
  35. loginButton.enabled = true;
  36. }
  37. else
  38. {
  39. loginButton.enabled = false;
  40. }
  41. }
  42.  
  43. private function onUsernameFocus(event:FocusEvent):void
  44. {
  45. switch (event.type)
  46. {
  47. case FocusEvent.FOCUS_IN:
  48.  
  49. if (usernameInput.text == defaultUsernameText)
  50. {
  51. usernameInput.text = "";
  52. }
  53.  
  54. break;
  55.  
  56. case FocusEvent.FOCUS_OUT:
  57.  
  58. if (Manager.isTextEmpty(usernameInput.text))
  59. {
  60. usernameInput.text = defaultUsernameText;
  61. }
  62.  
  63. break;
  64. }
  65. }
  66.  
  67. private function onLogin(event:MouseEvent):void
  68. {
  69. if (messageLabel.text != "")
  70. {
  71. message = "";
  72. }
  73.  
  74. dispatchEvent(new LoginEvent(LoginEvent.LOGIN, usernameInput.text, passwordInput.text));
  75. }
  76.  
  77. private function onRegisterAccount(event:MouseEvent):void
  78. {
  79. dispatchEvent(new LoginEvent(LoginEvent.REGISTER_ACCOUNT));
  80. }
  81.  
  82. public function cleanUp():void
  83. {
  84. removeAllElements();
  85. logo.bitmapData.dispose();
  86.  
  87. logo = null;
  88. usernameInput = null;
  89. passwordInput = null;
  90. messageLabel = null;
  91. loginButton = null;
  92. defaultUsernameText = null;
  93. }

Hope that you learn in this tutorial. And for more updates and programming tutorials don't hesitate to ask and we will answer your questions and suggestions. Don't forget to LIKE & SHARE this website.

 

Tags

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.