Skip navigation
Domhnall Ó Suibhne
Currently Being Moderated

setting the focus from stage to text field

Jun 26, 2012 5:21 AM

Tags: #text #field #action_script_3 #flash_cs5 #stage.focus

I am writing a program which requests that a user inputs a word into a text field which appears when a key is pressed. The input text is then checked against an array of  words. This works fine, however if  the stage .focus is changed from the stage to the text field so that there will be a flashing cursor ready in the text box o receive the users input, the input word will not be checked against the array. The program will not run. the  mytextfield.focus  works to the point where the cursor is in the tet field and receives the text etc but it then says that the word is not in the array. It fails to check it properly. Im 3 days trying to sort it and the only way it works is if the user has to click into the box which is what I dont want. Also is there a way of showing the textfield background as white without having an error message about it?

 
Replies
  • Currently Being Moderated
    Jun 26, 2012 5:30 AM   in reply to Domhnall Ó Suibhne

    You should show the code that is relevant to your problem

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 26, 2012 8:19 AM   in reply to Ned Murphy

    Are you running the check on the "change" event of the TextField? If not that'd be how I'd check against your array:

     

    http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fla sh/text/TextField.html#event:change

     

    Every time it's changed I'd check it.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 28, 2012 5:23 AM   in reply to Domhnall Ó Suibhne

    You can always get an event sent every time a character is typed and analyze it every keystroke, or just once when enter is pressed. Here's an example that excludes any analysis code but uses the event I mentioned above.

     

    http://pastebin.com/iJE2Fcrk

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 28, 2012 7:37 AM   in reply to Domhnall Ó Suibhne

    The person needs to have at least clicked "somewhere" on the application to give it focus in Windows. After that, you definitely can add the cursor blinking at the end if that's what you want.

     

    myTextField.setSelection(myTextField.length,myTextField.length);

     

    That will put the blinking cursor at the end of the TextField. If you want it in a specific position or to select a specific character you can just change the begin and end index values. Here's more info:

     

    http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fla sh/text/TextField.html#setSelection()

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 29, 2012 6:04 AM   in reply to Domhnall Ó Suibhne

    Just set the TextFields text property to an empty string..

     

    myTextField.text = "";

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 29, 2012 10:39 AM   in reply to Domhnall Ó Suibhne

    You're welcome, please mark the thread answered if you have what you need.

     

    Good luck!

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points