Announcement

Collapse
No announcement yet.

Action Script Key Capture bugged out

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Action Script Key Capture bugged out

    Im in need of some help fixing some bugs in action Script. Please look through the following code which I have commented throughout to understand the nature of my problem...If anyone can point me in the right direction to resolve this issue I would be very grateful. Please be aware that I have very little experience with actionscript and I have spent a few days piecing the following together:

    Code:
    import flash.external.ExternalInterface;
    
    var textvalue:String = "";
    
    //set the player name in unrealscript then save to config then use that to find save file and load that from unrealscript
    function SetPlayerName(){
    	
    	ExternalInterface.call("SetPlayerName", textvalue );
    	LoadSaveFromFile();
    	
    }
    
    
    //function to call the loadgame function in unrealscript using the player name string
    function LoadSaveFromFile()
    {
    	
    	
    	ExternalInterface.call("LoadGame");
    		
    		
    }
    
    
    //capture user input for the login
    //this function is buggy code which will not clear correctly with backspace and will 
    //not re-initialize if player hits cancel and then comes back. 
    // For each iteration of canceling and returning to this screen the output is doubled ...i.e., I press "TOM"  it will output "TTOOMM" the third time it will output "TTTOOOMMM" and so forth
    //Backspace is also captured in the output indicated by < in the string I send to unrealscript.  
    //These problems Make this login a very tedious affair since any mistakes will require the user to restart the game
    
    
    var keyListener:Object = new Object();
    Key.addListener(keyListener);
    
    keyListener.onKeyDown = function()
    {
    	
    	textvalue = textvalue + chr(Key.getCode());
    	
    	 
    }
    
    
    //Return to main menu, attempts to reset all relevant variables but is not working correctly.
    function CancelToMainMenu()
    {
    	textvalue = "";
    	keyListener = undefined;
    	gotoAndPlay("mainMenu");
    }
    
    okBtn.addEventListener("click", this, "SetPlayerName");
    cancelBtn.addEventListener("click", this, "CancelToMainMenu");
    
    cancelBtn.focused = true;
    
    
    stop();
Working...
X