Mars714

Data Battle PlayerName code

Apr 28th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. var playerName; {
  3.  
  4.     function PlayerNameInput(): void { // call once to set everything up
  5.  
  6.         saveDataObject = SharedObject.getLocal("DataBattle/character/name"); // give the save data a location
  7.         saveDataObject.data.characterName = playerName;
  8.  
  9.         function addName(e: TouchEvent): void {
  10.  
  11.             var myTextBox1: TextField;
  12.             var txtPlayer: TextField;
  13.  
  14.             function captureText() {
  15.  
  16.                 myTextBox1.type = TextFieldType.INPUT;
  17.                 addChild(myTextBox1);
  18.                 addChild(txtPlayer);
  19.                 myTextBox1.addEventListener(TextEvent.TEXT_INPUT, textInputCapture);
  20.             }
  21.  
  22.             function textInputCapture(event: TextEvent): void {
  23.                 txtPlayer.text = event.text;
  24.             }
  25.  
  26.  
  27.             if (playerName == null) { // checks if there is save data
  28.                 trace("No Player data yet."); // if there isn't any data on the computer...
  29.             } else {
  30.                 trace("Player data found."); // if we did find data...
  31.                 loadData1(); // ...load the data
  32.             }
  33.  
  34.             function loadData1(): void {
  35.                 playerName = txtPlayer;
  36.                 trace("Data Loaded!");
  37.  
  38.             }
  39.  
  40.  
  41.         }
  42.  
  43.  
  44.     }
  45. }
  46.  
  47. function saveData(): void {
  48.     saveDataObject.data.characterName = playerName; // set the saved score to the current score
  49.     trace("Data Saved!");
  50.     saveDataObject.flush(); // immediately save to the local drive
  51.     trace(saveDataObject.size); // this will show the size of the save file, in bytes
  52. }
Advertisement
Add Comment
Please, Sign In to add comment