4 Replies Latest reply on Sep 25, 2006 8:18 AM by thunder.scripts

    Selecion Object

    thunder.scripts Level 1
      Can anyone give me a quick explanation about this object? I've read many articles, including the flash manual, but I can't get it to work.

      Suppose I have a textfield and I need to find out which part is selected, the first and last characters, what should I do?

      Thanks
      Fede
        • 1. Re: Selecion Object
          DazFaz Level 1
          var mouseListener:Object = new Object ();
          mouseListener.onMouseUp = function () {
          trace("first letter = "+eval(Selection.getFocus()).text.charAt(Selection.getBeginIndex ()))
          trace("last letter = "+eval(Selection.getFocus()).text.charAt(Selection.getEndIndex ()-1))
          };
          Mouse.addListener (mouseListener);
          //------Explantion------
          // "Selection.getFocus()"
          // This returns the text field name that has been selected or the focus is set upon.
          //
          // So then "eval(Selection.getFocus()).text" returns the text string that is within
          // the selected text field
          //
          // And then "eval(Selection.getFocus()).text.charAt" is saying return the character at
          // a specified position within the returned string
          //
          // Then we need to specify, with a number "PutMyNumberHere", what pisition within the string we are interested in
          // eval(Selection.getFocus()).text.charAt(PutMyNumberHere)
          //
          // Instead of a literal number we make flash find the number for us with "Selection.getBeginIndex ()"
          //
          // Because this method works on a zero index, meaning that space in any text field will be 0 then 1, 2 ,3 etc.
          //
          // This is why, to find the last character in the selection made, we put "Selection.getEndIndex ()-1"
          //---------------------
          • 2. Re: Selecion Object
            DazFaz Level 1
            Did this code work for you thunder.scripts. Feedback please.
            • 3. Re: Selecion Object
              thunder.scripts Level 1
              Sorry, I've been very busy this week and haven't had the chance to test it yet.
              I'll try to test it during this weekend and get back to you asap.

              Thanks!!
              • 4. Re: Selecion Object
                thunder.scripts Level 1
                Great, I think I understand how it works and how to use it now.
                Thanks!