4 Replies Latest reply on Apr 19, 2006 1:49 AM by Newsgroup_User

    Can anybody help?

      Guys.... I made a field and inside there is a word..... I want a specific letter to change colour when each letter is typed on the keyboard.. Please give me a script that could do this.....

        • 1. Re: Can anybody help?
          Level 7
          Not sure exactly what you wantedm hhis might give you sone ideas.

          Attach this behavior to a TEXT member on stage.

          on keydown me
          sprite(me.spriteNum).member.selection = [0, 0] -- remove edit hilite

          pos = offset(the key, sprite(me.spriteNum).member.text)
          if pos then
          sprite(me.spriteNum).member.char[pos].color = rgb(255, 0, 0)
          end if

          This hehavior finds the first letter that matches the pressed key and
          sets it to red, more code could find all occurances of the letter and
          could use a different color for each letter.

          Set the editable property of the text member to true in order to get
          keydown events directed to it.

          you could have a predefined color table of 26 unique colors

          colorTble = [rgb(255, 0, 0), rgb(0, 255, 0), rgb(0, 0, 255), rgb(128,
          128, 128)]

          withg a line like this to assign the color ( needs more code to handle
          caps out of range characters )

          sprite(me.spriteNum).member.char[pos].color = colorTble[ charToNum(the
          key) - charToNum("a")

          The first line is a code complication that attaching key handler
          directly to the editable text member introduces.

          Placing handler in a seperate script like a movie script or an on stage
          but out of sight editable text member would allow the displayed text
          member to be locked.
          • 2. Re: Can anybody help?
            Level 7

            Here's a reply to someon with a similar question.


            if you have a ton of keys to deal with the if-then code approach could
            get quite messy, using a case statement would help, or you could use a
            predefoned lookup table:

            -- the keycolors table can e any length it looks the actual key that was
            pressed, there's a problem with lower and upper (shift key down) letters
            requiring separate entries, some added lingo code could convert upper
            case letters to lower case.

            on keydown
            colorLetter the key

            on colorLetter c
            keyColors = ["g": rgb(0,255,0), "r": rgb(255,0,0), "b": rgb(0,0,255)]
            theColor = getaProp(keyColors, c)
            if voidp(theColor) then -- that key not in table
            else sprite(1).color = theColor
            -- disable the line below in final product
            put theColor -- reports to message window if stage window is front

            -- alternative using the keycode where shift key doesn't effect things
            -- on my system A S D have keycodes 0, 1, 2

            on keydown
            put the keycode
            colorKey the keycode

            on colorKey c
            keyColors = [5: rgb(0,255,0), 15: rgb(255,0,0), 11: rgb(0,0,255)]
            theColor = getaProp(keyColors, c)
            if voidp(theColor) then -- that key not in table
            else sprite(1).color = theColor
            put c && theColor -- reports keycode and found color
            • 3. Re: Can anybody help?
              NismoBrothers Level 1
              Is there anyway that this can occur in field members not text.... if so can you alter the script so that it works... thanks
              • 4. Re: Can anybody help?
                Level 7
                See if you can do your own translation, here's an example of the old non
                dot syntax that appear to be needed for a field member.

                the forecolor of char 4 to 8 of member 1 = 34

                THe forecolor/backcolor color properties are 8 bit color palette entry
                numbers, rathe r than the rgb color color and bgColor use.