views:

15

answers:

2

I have a 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 = "";
    }
};

Still no luck. Can anyone tell me what I might be doing wrong?

A: 

try this on the first frame of the input_text movie:

nam.onSetFocus = function() {
    nam.text = "";
}

(...and make sure that nam is present in the first frame)

Also make sure you've set the textfield type to be "Input Text" (there's an option for this in the Properties window.


EDIT:

To initialise nam (on your first frame):

_root.input_text.nam.text = "NAME";
Richard Inglis
A: 

No luck I'm afraid.

Just wondering if this could be getting in the way though:

_root.input_text.nam = "NAME";

It is on the first frame of the scene.

rickstyphilis
If that's meant to be initialising the textfield, it should be _root.input_text.nam.text = "NAME";
Richard Inglis
Richard, you're a damn genius. Thanks for pointing that out.Problem solved; case closed.
rickstyphilis
No worries, glad to help. And nothing says 'thanks' like accepting an answer (just click on the big tick-mark beside this answer)!
Richard Inglis
No wait, this is YOUR answer... try accepting mine. Thanks :)
Richard Inglis