9 Replies Latest reply on Jan 28, 2007 4:01 PM by Newsgroup_User

    highlighting an editable text sprite

    Level 7
      I have a bunch of form type of pages on my stage. User enters text,
      jumps to a new screen, edits more text. Typically, the cursor will be
      blinking at the sprite in the lowest channel, which would ebbe my top
      item on the page. Sometimes, I may have form1 that has the same text
      member as form 2. If, in form1, you clicked text2, then go to form2,
      which also has that text in slot 2, the cursor shows there instead of
      the top text sprite (slot1). How would I fix that? And what if I wanted
      text 3 to have the cursor ? How would I get the cursor to be set to a
      specific text sprite and how would I get it to be highlighted like if
      you selected all the text in that member?

      Hope that was clear.

      Thanks.

        • 1. Re: highlighting an editable text sprite
          Level 7
          You can set the placement of the cursor using the keyboardFocusSprite.
          To set the editable text sprite that is in channel 3 as the current one
          with the cursor, you could do this:

          the keyboardFocusSprite=3
          • 2. Re: highlighting an editable text sprite
            Level 7
            Mike Blaustein wrote:

            > You can set the placement of the cursor using the keyboardFocusSprite....
            >
            > the keyboardFocusSprite=3

            Hi Mike,

            Want to help debug something I'm doing in this area. I'm also using 'the
            keyboardFocusSprite' but with a variable. Variable can keep increasing
            (when you click a button, a new item is added and the next editable text
            should become active). The first time I click the 'add' button, it works
            OK, but subsequent times, it does not work.

            Here's a sample of my code for the add button:
            gWelcomeNamesList.add([#name : "New Name", #image : ""])
            s = gWelcomeNamesList.count
            put s
            repeat while s > 8 -- there are 8 items on my list
            s = s - 8
            end repeat

            put s
            spriteFocus = 9 + (s * 7) -- formula based on where editable sprites are
            in Score
            put spriteFocus
            the keyboardFocusSprite = spriteFocus
            put the keyboardFocusSprite

            In my Message window, I can see the list count gets bigger each time I
            click (first s)
            Gets the position of the sequence of 8 correct (second s)
            get the spriteFocus value correct
            'the keyboardFocusSprite = spriteFocus' -- works the first time
            second time 'the keyboardFocusSprite = spriteFocus' doesn't seem to be
            activated. The last line 'put the keyboardFocusSprite' still shows the
            focus to be the prior sprite, not the new one which is now accurately
            defined by 'spirteFocus'.

            That make sense? Any ideas?

            regards
            Dean

            Director Lecturer / Consultant
            http://www.fbe.unsw.edu.au/learning/director
            http://www.multimediacreative.com.au

            • 3. Re: highlighting an editable text sprite
              Level 7
              You're gonna have to give me a little more before I can tell you whats
              going on with your code. I tried what you posted, and it works for me.
              In addition to the add button, I set a global gWelcomeNamesList=[]
              (empty list). I have 3 editable text sprites in channels 16,23,and 30
              respectively. Each time I hit the Add button with the code you
              provided, the correct sprite gets the keyboard focus (16 then 23 then
              30). If I hit the Add button again, then it looks for the next editable
              sprite which should be in channel 37. I don't have one there, so that
              final put correctly tells me that 30 is still the focus. It can not set
              the keyboardFocusSprite to a channel that is empty or has no editable
              text sprites.

              How is your file setup and what is it doing wrong?

              -Mike
              • 4. Re: highlighting an editable text sprite
                Level 7
                Hi Mike,

                Yep, I thought that wouldn't be enough. Though I hoped that maybe by writing
                it out, I'd see something and find the solution. There are a few other
                things happening so maybe that's what's causing the issue. The weird thing
                is that I have
                put variableName
                the keyboardFocusSprite = variableName
                put the keyboardFocusSprite
                variableName shows the right value
                but next line does not apply because
                result of third line is not the same as variablaName.

                Will see what I can do.

                regards
                Dean

                Director Lecturer / Consultant
                http://www.fbe.unsw.edu.au/learning/director
                http://www.multimediacreative.com.au


                • 5. Re: highlighting an editable text sprite
                  Level 7
                  One thing that may be an issue is that when you are setting

                  the keyboardFocusSprite = variableName

                  That may fail if sprite(variableName) is not an editable #text or #field
                  sprite. In that case, it will not change the keyboardFocusSprite at
                  all, so your next put will show the old keyboardFocusSprite and
                  variableName will still be the new number.
                  • 6. Re: highlighting an editable text sprite
                    Level 7
                    Mike Blaustein wrote:

                    > One thing that may be an issue is that when you are setting
                    >
                    > the keyboardFocusSprite = variableName
                    >
                    > That may fail if sprite(variableName) is not an editable #text or #field
                    > sprite. In that case, it will not change the keyboardFocusSprite at
                    > all, so your next put will show the old keyboardFocusSprite and
                    > variableName will still be the new number.

                    I thought that might be an issue because I am switching the editable
                    property on and off. But, just put a
                    put (sprite(variableName).member).editable
                    before 'the keyboardFocusSprite' and got a value of 1. So, it has been made
                    editable. Just don't understand why it's not changing the keyboard focus. If
                    I run a 'the keyboardFocusSprite' in teh message window, i can change it to
                    that sprite...

                    regards
                    Dean

                    Director Lecturer / Consultant
                    http://www.fbe.unsw.edu.au/learning/director
                    http://www.multimediacreative.com.au



                    • 7. Re: highlighting an editable text sprite
                      Level 7
                      Is there some other script running that may override this one? It could
                      be that this is correctly changing the focus, but then something else
                      changes it back?

                      I'm kind of grasping here...
                      • 8. Re: highlighting an editable text sprite
                        Level 7

                        Mike Blaustein wrote:

                        > Is there some other script running that may override this one? It could
                        > be that this is correctly changing the focus, but then something else
                        > changes it back?
                        >
                        > I'm kind of grasping here...

                        Probelm solved:)

                        I'll tell you how in a minute, Will write it out now. Want to try guess
                        whileIi'm writing the solution?

                        regards
                        Dean

                        Director Lecturer / Consultant
                        http://www.fbe.unsw.edu.au/learning/director
                        http://www.multimediacreative.com.au


                        • 9. Re: highlighting an editable text sprite
                          Level 7
                          > Probelm solved:)

                          Thanks Mike, you did lead me to a solution.

                          Script was changing editable property of text. So I had something along the
                          lines of
                          1. add item to list
                          2. change the matching member to editable
                          3. work out which sprite it is
                          4. change the keyboardFocusSprite to that sprite

                          The above was all done through a single event - mouseUp. And when I monitored
                          the values in the Message window, all looked OK. While the values were being
                          changed as that code of was read, something wasn't changing until the end of
                          the handler - the editable text property,

                          So the solution was to put an 'updateStage' between steps 2 and 3 above. That
                          would apply the change of the property and so when step 4 is read, the
                          editable property value is not just in memory but is actually the case, and
                          keyboardFocusSprite can work.

                          Are you happy to find a use of updateStage;)

                          regards
                          Dean

                          Director Lecturer / Consultant
                          http://www.fbe.unsw.edu.au/learning/director
                          http://www.multimediacreative.com.au