A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Clear Input Text on Click (AS 2.0)

  1. #1

    Clear Input Text on Click (AS 2.0)

    I have a simple form with an input text field with text in it. I would like that text to disappear when a user clicks on the input field. How is this done in Actionscript 2.0?

    Please view this page for the example:


    Thank you for any help!

  2. #2
    Junior Member
    Join Date
    Jan 2009
    yourMC.onSetFocus = function() {
    yourMC.text = "";

    // replace yourMC with whatever you name your input text field

  3. #3

    Where do I place the code?

    The form field is a movie clip. Do I just place the code in the first frame of the main movie? Thanks!!

  4. #4


    Nevermind, I figured it out - I had to place that code within the movie clip of the form field in the first frame. That worked! Thanks!

  5. #5
    Senior Member
    Join Date
    Aug 2009
    very useful, although I dont need it. At least now I know

    thanks also!

  6. #6
    Junior Member
    Join Date
    Jan 2009
    No problem. Welcome.

  7. #7
    Registered User
    Join Date
    Mar 2010
    I have a similar problem where I want a text field that by default has the word NAME in it, to become empty when a user clicks on it.

    The text field has the instance name 'nam' and is inside a movie with the instance name 'input_text'.

    I've searched around and found samples of code where everyone keeps suggesting this:

    textboxinstancename.onSetFocus = function() {
    textboxinstancename.text = "";
    should work. It seems to work for everyone else but me.

    I've tried using the following on the first frame of the 'input_text' movie with no luck:

    this.input_text.nam.onSetFocus = function() {
    this.input_text.nam.text = ""
    I've tried putting this on the first frame of the scene, again with no result:

    _root.input_text.nam.onSetFocus = function() {
    _root.input_text.nam.text = ""
    I've tried this in the same manner as the last respectively with both 'this' on the instance and '_root' on the scene (denoted by x):

    x.input_text.nam.onSetFocus = function() {
    if (x.input_text.nam.text == "NAME") {
    x.input_text.nam.text = "";
    (I like the idea of the this one as it will only reset if the word 'NAME' is in there.)

    Just wondering if this could be getting in the way:

    _root.input_text.nam = "NAME";
    It is on the first frame of the scene.

    Can anyone tell me what I might be doing wrong?
    Last edited by rickstyphilis; 03-17-2010 at 07:07 PM.

  8. #8
    Junior Member
    Join Date
    Mar 2010
    Hi Rick, it looks like you're on the right track, but you're having trouble targeting your textbox correctly (see here and here for more info on targeting and scope).

    Let's assume your setup is like this:
    [main timeline] contains [movieClip named 'input_text'] contains [textfield named 'nam']

    (and when I say named, obviously I mean the instance name of the object, as shown in the properties window)

    So if you want to target the contents of the textfield from the main timeline you can say:
    (ie set the text property of the 'nam' textfield in 'input_text' to "NAME")

    And if you want to set an onSetFocus action for 'nam' from the first frame of the 'input_text' movie, you can say:
    nam.onSetFocus = function() {
        nam.text = "";
    I've tested this, and it works - but perhaps my flash file is set up differently to yours?
    Anyway, if you need more help on this, go back to stackoverflow and edit your question from yesterday...

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