A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: cant remove focus from input text field

  1. #1
    Junior Member
    Join Date
    Mar 2006
    Posts
    19

    [F8] cannot remove focus from input textfield.[F8]

    Hi,
    I have a swf that is having problems only when I load a movie.

    someButton.onRelease = function(){
    empty_mc.loadMovie("C://maps/"+jpgName_txt.text+".jpg");
    }

    I noticed that the movie does not run right only when the cursor is still bliking in the input text field. I will input text in the input field but the cursor continues to remain in the field even after clicking the "someButton".

    I tried to change the function to

    loadMovie("c://maps/"+jpgName_txt.text+".jpg",empty_mc);

    but is still has a problem. The problem being that when I click another button in the program, sometimes it will not work and othertimes it will.
    When I remove the input field and hard code the import the loadmovie it works fine.

    Any idea???? I'm loosing my hair..........

    Thanks in advance.....[
    Last edited by quintje; 08-24-2007 at 02:59 PM. Reason: forgot to list flash version

  2. #2
    Junior Member
    Join Date
    Mar 2006
    Posts
    19

    found same problem but no solution....[F8]

    I found the same exact problem elsewhere but no solution. Please see this post.

    http://board.flashkit.com/board/show...t=remove+focus

    Thanks for the help if you know the solution.

  3. #3
    Developing For Dunkets mneil's Avatar
    Join Date
    Mar 2007
    Location
    Lincoln City
    Posts
    2,156
    This completely sucks. I just so happened by a forum today where someone had this problems and they fixed it and posted the answer. No other posts either; just the two and now I cant find it. I remember they solved it by setting the focus to the movie clip (button) but I don't remember where or when they did it. I think when they clicked the button they ran an if statement to check for focus and then setFocus to the mc if it wasn't in focus and did the actions. Sorry man, this is killing me. I'll let you know if I find it.
    http://code.mneilsworld.com/
    Text Effects | Bubbles | Dynamic Resize
    4 weeks , 20 papers ... thats 2 dollars .....Caassshhh!

  4. #4
    Junior Member
    Join Date
    Mar 2006
    Posts
    19
    Thanks for the help, as I was typing this I tried something and it actually worked. My problem isnt completely solved but it worked. Here is what i did.

    Selection.setFocus(loadjp_btn);

    After the user types in a name in my program they have to click the loadjp_btn.
    so I put the above in a function. Setting the focus on the button that was just clicked. Now the only problem is that I have to make the input text field non-selectable again or I will have the same problem. Then make it selectable again only if the user hits a reset button that I have provided as well.

    Thanks again..........

  5. #5
    Junior Member
    Join Date
    Mar 2009
    Posts
    2

    Removing focus from an input text field

    This issue was frustrating. I tried the suggestion to set Stage.focus = null; but that did not work. (Sometimes I wonder if people just publish fixes without actually checking to see if they actually work).

    In the end I cheated.
    I created an inputfield off stage and called it "dummy_txt" and then used _root.dummy_txt.setFocus();

    so we have the following block of code:
    /////Handle Enter key///////

    function myOnKeyDown() {
    // Enter Key Pressed
    if (Key.isDown(Key.ENTER)) {
    _root.dummy_txt.setFocus();
    }
    }
    var myListener:Object = new Object();
    myListener.onKeyDown = myOnKeyDown;
    Key.addListener(myListener);

    ////////////////////////////

    For the text field which I embed in a movieclip I add this code:

    field_txt.onKillFocus = function(newFocus:Object) {
    trace(this.text + ":" this._name);
    };

    And I replicate the clip each time I require an input field.
    Tracing by passing the name of the movie clip the field resides in and the text within the clip you can send the data to a common script and place it in a data Array you created in the parent clip. If you need to know the path to the text field just use this:

    field_txt.onSetFocus = function(newFocus:Object) {
    _root.selectedText = this
    };

    so you can reference it later.

    "Cheers big ears"

  6. #6
    Junior Member
    Join Date
    Jan 2010
    Posts
    1
    in as2, the following worked for me. Have a look at the as2 Language Reference under class Selection.setFocus(). ("If null or undefined is passed, the current focus is removed.") So no need for dummy field..

    var keyListener:Object = new Object();
    keyListener.onKeyDown = function() {
    if(Key.isDown(Key.ENTER)){
    Selection.setFocus(null);
    }
    Key.addListener(keyListener);


    Hope this helps someone!

  7. #7
    Junior Member
    Join Date
    Aug 2004
    Posts
    19
    Thank you very much duttski!

    Despite reading over the as2 focus material, i was still drooling and staring at carpet fibers until I saw your post, then it clicked.

    Problem was (if anyone cares) an input had an onKillFocus event on it that was triggering when users finished typing in an input field and clicked the submit button, but the submit button was removing the mc with the input at the same time (bad) which crashed the plugin. Easy fix was to add rollOver event to submit button that kills focus before it can be clicked.

    Thanks again!

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