6 Replies Latest reply on Jul 4, 2006 11:37 PM by flynnc

    Problem with listener

    flynnc Level 1
      As a flash newbie I am trying use a listener to watch for a user selecting a specific text box and clearing the temporary message it is displaying. When I use the code attached below, both text boxes clear when the user clicks.

      Can anyone help with this???

      //set shared object
      var test_so:SharedObject = SharedObject.getLocal("test", "/");

      //create initial text boxes and populate with text
      foreName.border = true;
      foreName.text = "<< Please enter forename here >>";
      surName.border = true;
      surName.text = "<< Please enter surname here >>";

      //set text format
      var txtFormat:TextFormat = new TextFormat();
      txtFormat.align = "center";
      txtFormat.bold = true;
      txtFormat.size = 18;
      txtFormat.color = 0x006600; // green

      //set up listener object
      var oListener_1:Object = new Object ();
      oListener_1.onMouseUp = function (){
      foreName.type = "input";
      foreName.text = ""
      // Handler for userName.onChanged
      foreName.onChanged = function(){
      test_so.data.fore = foreName.text;


      //set up listener object
      var oListener_2:Object = new Object ();
      oListener_2.onMouseUp = function (){
      surName.type = "input";
      surName.text = ""
      // Handler for surName.onChanged
      surName.onChanged = function() {
      test_so.data.sur = surName.text;

        • 1. Re: Problem with listener
          kglad Adobe Community Professional & MVP
          you don't need two listeners, you don't need to use an onSetFocus() handler and an onMouseUp handler and you shouldn't be using a string as any functions parameter. try:

          • 2. Re: Problem with listener
            Thanks for your reply Luigi.

            I thought it was a path problem too, and your response made perfect sense - -target the button inside the MC rather than the MC itself. But when I did that it still didn't work. So I decided to go the Occams Razor route and cut away all the extraneous items -- started with a fresh .fla. This new movie has only two frames, and one button -- a simple button this time, with no nesting of any sort.

            Frame one contains a stop command and the listener code for the button; the listener code tells the _root timeline to go to frame 2 and stop. Frame 2 contains a cloud shape, so I'll know easily if the button has worked or not.

            The button instance is called clicker_btn.
            The listener is called myListener.
            The button click still does not work, and I'm really pulling my hair out now.

            Here's the code that sits in Frame 1 of the new test file:

            // Pause frame 1 until button clicked

            // LISTENER
            var myListener:Object = new Object();
            myListener.click = function(evtObj) {
            clicker_btn.addEventListener("click", myListener);
            • 3. Re: Problem with listener
              ricklecoat Level 1
              Oops, I posted the above to the wrong thread. Still, it's about Listeners, so it's still faintly relevant. Apologies for the error.
              • 4. Re: Problem with listener
                flynnc Level 1
                Hi kglad,
                Thanks for your response to my problem.

                I tried the code you attached but for some reason when I select the text box the text remains. I don't know if I have something else missing from the code?

                Also I am using Flash 8 Professional.

                • 5. Re: Problem with listener
                  kglad Adobe Community Professional & MVP
                  that should be:

                  • 6. Re: Problem with listener
                    flynnc Level 1
                    Thanks for the help and code kglad that works great.