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

    How to get sprite number in a KeyUp script?

    czigany Level 1

      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.



        • 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)



          on updateEntrySpriteList me, senderSpriteNum


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



          on keyDown me

            case(the keycode) of

              36:  --Enter key

                myIndex = pEntrySpriteList.findPos(spriteNum)

                if myIndex = pEntrySpriteList.count then

                  the keyboardFocusSprite = pEntrySpriteList[1]


                  the keyboardFocusSprite = pEntrySpriteList[myIndex + 1]

                end if

              otherwise: -- Handles ordinary input


            end case


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

            Thanks. This example is very useful.