2 Replies Latest reply on Mar 6, 2012 11:20 AM by czigany

    How to get sprite number in a KeyUp script?

    czigany

      I have an app with a series of text entry fields. Users enter numeric values in each field. I want to have the keyboard focus move to the next field when the user clicks on the Enter key. So far I've only been able to do this by hard coding the number of the next sprite as follows...

      -----

        case(_key.keycode) of

          36:  --Enter key

            _movie.keyboardFocusSprite = 64 -- This is the hard-coded value of the next sprite

            numString = member("ALA_CFTHolder").text

           

          otherwise: -- Handles ordinary input

                ...

        end case

      -----

      I want to find a way to move to the next sprite without hardcoding the value. I've tried reading the _movie.keyboardFocusSprite but it's always -1. Surely there's a way to do this.

       

      Thanks.

        • 1. Re: How to get sprite number in a KeyUp script?
          Mister MUX Level 2

          See if this code helps you. It doesn't matter which sprite channel the fields are in, but the focus order is determined by the order in which the sprites appear on the score. If that isn't what you want a different approach will be required.

           

           

          ---------------------------------------------------------------------

          property spriteNum, pEntrySpriteList

           

          on beginSprite me

            pEntrySpriteList = []

            sendAllSprites(#updateEntrySpriteList, spriteNum)

          end

           

          on updateEntrySpriteList me, senderSpriteNum

            pEntrySpriteList.add(senderSpriteNum)

            if spriteNum <> senderSpriteNum then sprite(senderSpriteNum).pEntrySpriteList.add(spriteNum)

          end

           

          on keyDown me

            case(the keycode) of

              36:  --Enter key

                myIndex = pEntrySpriteList.findPos(spriteNum)

                if myIndex = pEntrySpriteList.count then

                  the keyboardFocusSprite = pEntrySpriteList[1]

                else

                  the keyboardFocusSprite = pEntrySpriteList[myIndex + 1]

                end if

              otherwise: -- Handles ordinary input

                pass

            end case

          end

          • 2. Re: How to get sprite number in a KeyUp script?
            czigany Level 1

            Thanks. This example is very useful.