6 Replies Latest reply on Nov 20, 2007 4:08 AM by Newsgroup_User

    Text Field

    qwertybloke
      I am working on a project that requires the user to type into a text field, however, the text output needs to be fixed/pre-defined so that the set "text" appears no matter what sequence of keys are pressed...

      Had thought to do this as a tween initialised by the 1st On KeyUp action, but I'm convinced that there must be a way to manipulate the text field...

      Any help very much appreciated.
        • 1. Re: Text Field
          Level 7
          Try pasting the following into a behavior script and attaching it to
          your #text sprite/s:
          --
          property spriteNum
          property myMember
          property myOriginalText
          property myKeyDownCount
          -- GPDL defined:
          property myText

          on isOKToAttach(me, sType, sNum)
          if ( sType = #graphic ) then return (sprite(sNum).member.type = #text)
          return FALSE
          end

          on getPropertyDescriptionList
          return [#myText: [#comment: "Text to appear:", #format: #string,
          #default: EMPTY]]
          end

          on beginSprite me
          myMember = sprite(spriteNum).member
          myOriginalText = myMember.text
          myMember.editable = 1
          myKeyDownCount = 0
          end

          on keyDown me
          myKeyDownCount = myKeyDownCount + 1
          if ( myKeyDownCount <= length(myText) ) then
          myMember.text = myText.char[1..myKeyDownCount]
          end if
          stopEvent
          end

          on endSprite me
          myMember.text = myOriginalText
          end
          • 2. Re: Text Field
            qwertybloke Level 1
            Thanks, but I'm getting the following Error message:


            Script error: Operand expected

            return [#myText:[#comment: "Text to appear:",#format:#string,?



            • 3. Re: Text Field
              Level 7
              The newsgroup probably inserted a rogue line break. That block should
              three lines of code. There is one line for the 'on
              getPropertyDescriptionList' and then one line of code, then the 'end' on
              the 3rd line.
              • 4. Re: Text Field
                qwertybloke Level 1
                Thanks, changing the block to 3 lines of code worked & the Error code has gone.

                But, when I play the movie and type in the text field the output from my actual keystrokes show, not the pre-defined "Text to appear:" from the behavior code.

                Hope I'm not sounding like a complete dunce.
                • 5. Re: Text Field
                  Level 7
                  Make sure it is set as a behavior and make sure you put it on the text
                  sprite. It should work.
                  • 6. Re: Text Field
                    qwertybloke Level 1
                    I was being a dunce!

                    I needed to add the text I wanted to appear to the text sprites Behaviour Parameters.

                    Working perfectly now.

                    Huge thanks for your help