7 Replies Latest reply on Mar 23, 2007 4:31 PM by Newsgroup_User

    Remove ENTER from a field

    wgb14 Level 1
      Hi all,

      I would like to create a bahaviour that removes on mousedown the ENTER constant from a text field. Is it possible to do that?

      My problem is that i have a field in which i want my user to copy text from word. However becuase the text includes ENTER my text int he field comes with a small sqaure (propably representing the enter) at the beginnign of each line. Is it possible to remove that?

      Many thanks
        • 1. Re: Remove ENTER from a field
          wgb14 Level 1
          Apparently this Enter constant is an empty line between my text (below). I am not sure how to remove it! Any ideas will be appreciated


          Yes, I didn't understand a part of your description, can you help?
          --this is where the problem lies! Any ideas how to remove these empty lines?
          Yes, I do have some questions about this location!

          I would like to continue to the next destination in our tour, how can I do that?

          thanks
          • 2. Re: Remove ENTER from a field
            Level 7
            I can't see anything wrong with what you posted - but that probably
            because I'm using a news reader not the web interface.
            Windows uses carriage return + line feed (CRLF) characters for its new
            line, Mac uses a carriage return (CR) (Director's RETURN constant) and
            Unix uses a line feed (LF).
            It's probably the linefeed characters that are showing as boxes. You can
            remove them by searching for numToChar(10) and replacing them with
            EMPTY, or using a regular expression with either pregex or a JS function
            to do a replace.
            --
            LF = numToChar(10)
            repeat while TRUE
            tPos = offset(LF, aString)
            if offset = 0 then exit repeat
            delete char tPos of aString
            end repeat
            • 3. Re: Remove ENTER from a field
              Lukewig Level 1
              Hi,

              You can stop users from entering a RETURN or ENTER by adding a behaviour like this to your editable text or field sprite:

              on keyDown (me)
              k = the key
              if (k = ENTER) or (k = RETURN ) then
              stopEvent
              else
              pass
              end if
              end

              Otherwise, if you want to remove it on mouseDown, then do this:

              on mouseDown (me)
              m = sprite(me.spriteNum).member
              re = "\n" -- regexpression describing what you want to remove
              m.text = RegExp_Replace(m.text, re, " ", "g")
              end

              ( note - this assumes you have DirectorMX2004 and have added this script ( http://www.lingoworkshop.com/code/classes/scripts/JS_RegEx.ls) to your movie)

              Cheers,
              Luke
              • 4. Re: Remove ENTER from a field
                wgb14 Level 1
                Many thanks to BOTH of you!!!
                • 5. Re: Remove ENTER from a field
                  wgb14 Level 1
                  I have only one question

                  re = "\n" -- regexpression describing what you want to remove

                  I am not sure what is the above or where do you define that is the ENTER character! Could you please explain further?

                  Many thanks
                  • 6. Re: Remove ENTER from a field
                    Lukewig Level 1
                    Hi,

                    In a regular expression (and probably Javascript generally), "\n" refers to the Line-Feed character - I am assuming this is the character that is giving you grief. You might be able to also use \x0D or \x0A (I forget which is a RETURN and which is a NEW LINE character). Other common characters include \r (return) and \t (tab).

                    Some really usefully character classes for use in regular expressions include

                    \w = any 'word' character (letters and digits)
                    \W = any non 'word' character (punctuation etc)
                    \d = any digit character
                    \D = any non digit
                    \s = any white space
                    \S = any non white space

                    See http://www.regular-expressions.info/reference.html

                    Once you get your head around them (they can be really confusing at first), Regular Expressions are one of the most useful programming things you can learn

                    Cheers,
                    Luke

                    • 7. Re: Remove ENTER from a field
                      Level 7
                      Note that if you're using any version of Director prior to MX 2004, you
                      can't use the Javascript expressions. numToChar(10), and numToChar(13) are
                      the usual culprits, depending on whether you're on Mac or PC. You'll want
                      to get rid of both to make sure.