|
-
having trouble with onSetFocus
I have searched far and wide, seen thousands of similar problems and thousands of solutions, and none of them are working for me.
I know it has to be simple, I have done it many times before, but this time it just won't work.
I am trying to remove text in an input text field when the text field gains the focus (from being clicked on)
So basically I have a username input text field, that says "Enter Username Here"
When it is clicked on I want this text to disappear...
I have tried many variations of the following:
Code:
username.onSetFocus = function() {
this.text = "";
};
Now... getting it to work in anyway possible will help a lot. Getting it to work within an external .as file will help even more, and getting it to work with an external .as file and with a var name and an instance name would be optimal.
Thanks guys.
If I am wrong, please just correct me and move on.. there is no need for all that pointing and laughing! ~MoN
-
that's AS2. this is the AS3 board. are you trying to find the equivalent in AS3? and, clarify what you mean by external .as file, var name and instance name - that isn't clear to me - do you want a class that extends TextField that automatically has that behavior?
-
Yes, sorry my post was incoherent. I am looking for this to happen:
On stage I have several buttons, each is controlled by code in an external .as file (fla is named "buttonGame.fla as file is gameEngine.as)
All of the buttons work just fine. On the movie I added an input box for the player to enter their username. This project is connected to a database that will add the username to the database and allow the player to log in and out.
For space limit reasons I can't have Username:{ text box here} so I decided to put "Enter your Name here" as the default text inside the input box when that page comes up. This works.
What I want to happen is to have the "Enter Your Name Here" text to disappear when the player clicks inside the textbox.
Because of the database checking (and the php/sql that is involved there) I have to give the textbox a var name, which I did: "uname" But to control the text inside the box I have also had to give it an instance name, which I did: "uName"
I have added the code (the onSetFocus) to both the external AS file as well as on the actual timeline of the fla. Neither will remove the text when clicking on the box.
Hope that clears it up.
I am hoping to get an AS3 conversion, but if it will work in AS2, then I can do that as well. At this point I have no preference.
~MoN
If I am wrong, please just correct me and move on.. there is no need for all that pointing and laughing! ~MoN
-
not sure which is the actual textfield: uname or uName - your post calls them both textboxes, but obviously you can have a textfield inside another... for the example, i'll pretend it's uName - change that if appropriate
PHP Code:
function clearText(event:Event):void{ TextField(event.currentTarget).text = ""; } uName.addEventListener("focusIn", clearText);
-
hmmm... I am getting this error:
The class or interface 'Event' could not be loaded. function clearText(event:Event):void{
Ideas?
Edit:
Heh. I guess I could add the event to the package, eh? :P
Thanks!
Last edited by MasterofNothing; 02-05-2010 at 09:33 PM.
If I am wrong, please just correct me and move on.. there is no need for all that pointing and laughing! ~MoN
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|