A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Text input component and onfocus

  1. #1
    Member
    Join Date
    Oct 2006
    Posts
    45

    Text input component and onfocus

    Hello all,
    Does anyone know a simple actionscripted way of deleting the initial text of a text input component on focus then return that text on blur if nothing was input? All I can find online is all of these bulky event listener methods. Frankly, it's seems easier to do this form input crap in javascript with standard HTML elements than mess with Flash.

  2. #2
    Senior Member Ovaire d'Oz's Avatar
    Join Date
    May 2006
    Location
    France
    Posts
    148
    To detect the focus, you can use TextField.onSetFocus and the equivalent to onBlur is TextField.onKillFocus.
    To set back the old value you could try something like this:
    TextField.onSetFocus = function(){
    myValue = TextField.output.text;
    TextField.output.text = "";
    }
    TextField.onKillFocus = function(){
    if (TextField.output.text == ""){
    TextField.output.text == myValue;
    }
    }

  3. #3
    Member
    Join Date
    Oct 2006
    Posts
    45
    At first it didn't work, but with some adjustments I got the focus part to work:
    Code:
    var theSearchBox = _root.searchBox.searchbox;
    
    theSearchBox.onSetFocus = function() {
    	var myValue = theSearchBox.text;
    	theSearchBox.text = "";
    }
    theSearchBox.onKillFocus = function() {
    	if (theSearchBox.text == ""){
    		theSearchBox.text = myValue;
    	}
    }
    The onKillFocus, however, is not working. It doesn't even appear that clicking outside the text input is allowing it to kill the focus, which may be the problem. FYI, I'm using AS2.

  4. #4
    Member
    Join Date
    Oct 2006
    Posts
    45
    I noticed that the focus is killed when I click out of the entire flash movie, not just out of the text input area. That's annoying. Any ideas why?

  5. #5
    Senior Member Ovaire d'Oz's Avatar
    Join Date
    May 2006
    Location
    France
    Posts
    148
    I suppose Flash thinks that if you click outside the movie, you will not want to interact with it any longer. Annoying, probably, but I am sorry to say that I don't have any solution.

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