Clearing text in an Input Text Field

If I wanted to create a button that would clear all text a visitor has typed into a separate text box, named “page”, how would I do that? I’ve tried using the following actionscript on the button but to no avail:

on (release) {
_root.page = " ";
}


on (release) {
_root.page.text = " ";
}

Hmm…that didn’t work either…?

That script should go with the button, yes?

it works fine for me - post a fla or email it to me and i will try to fix it…before you do, double check all your instance naming, referencing and syntax, as there is no reason why _root.page.text = " "; shouldnt work if the input textfield is really on the _root. timeline and is called “page”.

Here’s the file (kitties.fla)

I want to make the star-like button at the top left clear the text field in the middle.

Maybe I’m having problems because the text field is in a movie clip? It works fine for another button I have that prints the text field (the piece of paper). But I’m fairly new at Actionscript so perhaps I’m missing something really basic… As far as I can tell everything is named correctly…

Thanks for your help on this!

i just looked at your FLA…

just use _root.page.page.text

instead of _root.page.text

That should work.

Good luck

when in doubt use the “target path” button from the Actions pane - that has saved me a lot of headaches…

did it work vpmiyu?

Thanks for all your suggestions!

Actually, putting in page.page worked to clear the field when the swf was opened, but if I typed in words and then pressed the button, it didn’t clear them. Why woud that be?

ok i renamed the input text inside the “page” movie clip to “textbox”. I also renamed the input text’s variable to “pageVar”.

it works fine using


on (release) {
	_root.page.textbox.text = "";
}

its not a good idea to use the same word for so many things, ie the movie clip called “page”, then you called the textbox inside it “page” again, then you called the variable for the textbox “page” again :crazy:

use descriptive instance naming :thumb:

Ah hah! It works!

Thanks a ton. Next time I will use better naming! I had thought that if I named everything similar with that movie clip, it would make things easier. Heh. :ne: I guess that’s what you get when you’re new to actionscript!

Thanks to both of you for helpin me out! :smiley:

:thumb: great! glad to be off assistance :wink: