A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: Backspace sends to previous page in an input textfiled !

  1. #1
    Member
    Join Date
    Feb 2003
    Posts
    33

    Backspace sends to previous page in an input textfiled !

    Hi All,
    I have a strange behavior with a flash 8 game that seems only to happen on Explorer6.

    When hitting the 'Backspace' key to edit a text entered in a flash input textfield, users are redirected to previous html page !

    - users do NOT accidentally click outside the flash before hitting backspace, the focus is on the flash texfield
    - I even catched the backspace in the html page with javascript and bloqued it (backspace is inefficient when focus is on the browser) but the problem still occurs !
    - the problem does not seem to be linked to the flash named anchor problem

    any idea to fix this ?

    thanks 1000 times in advance

  2. #2
    Senior Member
    Join Date
    Oct 2007
    Posts
    146
    Did you use a number system for the keys? example 37 (left arrow)?

  3. #3
    Member
    Join Date
    Feb 2003
    Posts
    33
    not really,
    I'm just using a regular text input field with a submit button to let the user enter text, and I just intercept the ENTER key to submit the answer (AS code below)

    Key.addListener(this);
    this["onKeyDown"] = function() {
    if (Key.isDown(Key.ENTER)) {
    this.doSomething();
    }

  4. #4
    Senior Member
    Join Date
    Oct 2007
    Posts
    146
    Try the following:

    PHP Code:
    Key.addListener(this);
    this["onKeyDown"] = function() {
    if (
    Key.isDown(46)) {
    this.doIt();    

    "46" is the numeric value for the delete key.

  5. #5
    Senior Member
    Join Date
    Oct 2007
    Posts
    146
    Backspace would have a value of "8"

    so, it would look like:

    Key.addListener(this);
    this["onKeyDown"] = function() {
    if (Key.isDown(8)) {
    this.doIt();
    }

  6. #6
    Member
    Join Date
    Feb 2003
    Posts
    33
    Westink, I don't really want to intercept backspace, I just don't want it to send me back to previous page !
    Are you suggesting that adding code handling the backspace code would prevent this unwanted behaviour (that only happens on explorer) to happen ?

  7. #7
    Senior Member
    Join Date
    Oct 2007
    Posts
    146
    Aside from setting properties for browsers (HTML end) I can only think of controling it through the swf, and the assigned keys. It could work through textField for example:

    var inputField: TextField = this.createTextField("inputField", 1, 120, 50, 100, 20);
    inputField.type = "input";
    inputField.text = "value";

    Set another variable with a string class and another for its length (ie. inputLength:Number).

    Your method, key(8) should include which number(s) in the length to take out.

  8. #8
    Member
    Join Date
    Feb 2003
    Posts
    33
    Westink,
    thanks for taking the time to answer, but I'm not sure I understand your proposal.

    I already have a listener on key events, that does submit the content of the textfield when RETURN is pressed.
    Of course I could add a test on Backspace and do something if I recognize backspace, like you suggest in your snippet
    Code:
    if (Key.isDown(8)) { 
    this.doIt(); 
    }
    but what could I do with flash to prevent the browser from capturing also this backspace event and doing that browser.back action ?

  9. #9
    Senior Member
    Join Date
    Oct 2007
    Posts
    146
    I believe, and this just a belief, that if you script the logic of (8), backspace, then you are trumping any browser control. Meaning, the script in the swf gives control over that button. So, if you decide to give the backspace a function of moving backward in the text index, then it will do so despite the fact that THE STUPID WINDOWS window is wanting giving a specific command.

    Also, check your internet options. I'm sure windows has a setting that turns those shortcut commands off. I would hope so! IE stinks, thumbs down to that garbage.

  10. #10
    Member
    Join Date
    Feb 2003
    Posts
    33
    unfortunately this does not work ...
    I captured the backspace event in flash (which become inefficient as expected on my test environment), but it still acts as a browser back on the customers having the problem.

    Any other suggestions here ? Please gurus advise !

  11. #11
    Senior Member
    Join Date
    Oct 2007
    Posts
    146
    Does anyone know if this is browser specific, which it sounds? And is there a way to turn that stupid thing off?! While you are at it, can you please give Bill Gates a MONSTER GRUNDY!

  12. #12
    Junior Member
    Join Date
    Nov 2007
    Posts
    3

    IE6 Workaround

    For programming this workaround, people might think I have too much time - which I have not - but I needed to get this to work:

    In your html do something like this:
    Code:
    <head>
    <script type="text/javascript">
    	function interceptKeys(keyCode)
    	{
    		//ASCII Code 8 = Backspace, Code 9 = Tab
    		if (keyCode==8 || keyCode==9)
    		{
    			var flash = (navigator.appName.indexOf ("Microsoft") !=-1)?window["flash_id"]:document["flash_id"];
    			flash.externalKeyPressed(keyCode);
    			return false;
    		}
    		
    		return true;
    	}
    </script>
    </head>
    <body onKeyDown="return interceptKeys(self.event.keyCode);">
            <embed id="flash_id" ... />
    </body>
    And inside your flash movie do the following:
    PHP Code:
    import flash.external.*;

    ExternalInterface.addCallback("externalKeyPressed"thisexternalKeyPressed);

    function 
    externalKeyPressed(keyCode)
    {
        if (
    keyCode == Key.BACKSPACE)
        {
            var 
    input_txt:TextField = eval(Selection.getFocus());
            if (
    input_txt && input_txt.removeTextField && input_txt.type=="input"//any better way to find out wether this is an input TextField and any TextField at all?
            
    {
                var 
    beginPos:Number Selection.getBeginIndex();
                var 
    endPos:Number Selection.getEndIndex();
                if (
    beginPos == endPos)
                    
    beginPos-=1;
                
    input_txt.text input_txt.text.substr(0,beginPos)+input_txt.text.substr(endPos);
                
    Selection.setSelection(beginPos,beginPos);
            }
        }
        else if (
    keyCode == Key.TAB)
                {
    /*Do something sensible with TAB*/}

    This will pass the keys Backspace and TAB to the flash function externalKeyPressed. Unfortunately I wasn't able to find a flash function that emulates a keyDown-Event. So I rebuilt the functionality of the backspace key. It will only work with text inputs!
    In my case the TAB key also went to the browser, so I redirected that too. However, my code to emulate tab order was too ugly, so I refrained from posting it here ;-)

    After doing all that I wondered if there wasn't an easier way to accomplish this. My flash opens in a javascript popup and I realized that when I hit Backspace it started deleting things in the URL-input of the opener window. So I tried putting self.focus(); in the body onload of the popup, but that just took away the focus from the flash inputs completely... Any thoughts?
    For Firefox2 it was enough to put a flash.focus() somewhere in the javascript code. I didn't try it with IE7 (only offline, but it doesn't work in either browser offline - only online)
    Last edited by lentschi; 11-27-2007 at 10:43 AM.

  13. #13
    Senior Member
    Join Date
    Oct 2007
    Posts
    146
    Far too much time, and that's a good thing!!!!!! THANKS.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center