3 Replies Latest reply on Feb 2, 2008 10:41 AM by robdillon

    How do I change a TextInput component on focus?

    asiabackpacker Level 1
      I have the following code. Can anyone give me any idea of why this isn't working?

      var oListener:Object = new Object();
      oListener.onSetFocus = function(oEvent:Object):Void {
      trace(oEvent.target.selectedItems);
      };

      name_txt.addEventListener("click", oListener);

      I want to ultimately change the background color of the text field when the user clicks inside of it. I can find almost no information on this anywhere, including in the Flash documentation. Can anyone give me any pointers on doing this and/or tell me what I am doing wrong here.

      Thanks!
      Elliott
        • 1. Re: How do I change a TextInput component on focus?
          asiabackpacker Level 1
          OK, I got this to work....kinda:

          var oListener:Object = new Object();
          oListener.onSetFocus = function(oldFocus, newFocus) {

          trace("oldFocus: " + oldFocus);
          trace("newFocus: " + newFocus);
          trace("Selection.getFocus(): " + Selection.getFocus());
          trace("");

          };

          Selection.addListener(oListener);

          The problem is, the newFocus variable targets the label, ie:

          newFocus = "_level0.subject_txt.label"

          But I want to target:

          _level0.name_txt.setStyle("backgroundColor", "0x000000");

          (ie: without the "label" part of the path)

          Does anyone have any idea how to do this?

          Do you need me to clarify what I'm asking?

          Thanks,
          Elliott
          • 2. Re: How do I change a TextInput component on focus?
            asiabackpacker Level 1
            Anyone???

            Here it is explained again (maybe a little clearer).....

            Here's the code I'm using:

            var oListener:Object = new Object();
            oListener.onSetFocus = function(oldFocus, newFocus) {

            trace("oldFocus: " + oldFocus);
            trace("newFocus: " + newFocus);
            trace("Selection.getFocus(): " + Selection.getFocus());
            trace("");

            };

            Selection.addListener(oListener);

            Clicking on any input field in my form triggers the function, as it should. The challenge is, I want to get the name of the field. What the function returns for newFocus is:

            _level0.subject_txt.label

            But I can't target it correctly with "label" on there:

            What I want to do is target the setStyle property, like this:

            _level0.name_txt.setStyle("backgroundColor", "0x000000");

            Does anyone have any idea how to do this?

            Thanks,
            Elliott
            • 3. Re: How do I change a TextInput component on focus?
              robdillon Most Valuable Participant
              AddEventListener() is an AS3 function. Are you working in AS3 or AS2?

              If you're actually working in AS2 then here's a solution for you. I'm guessing that you're using an input textfield with the name of name_txt. If that's the case then add this code to a frame action space where the textfield exists: