8 Replies Latest reply on Jun 13, 2006 8:48 PM by morningstar

    scrolling text with keyboard

    morningstar
      Hi,
      I need for text in a textfield to scroll using the keyboard arrow keys instead of the scrollbar (which is done automatically in Flash). I tried using the following script I found on this site but could not get it to work:

      scrollrate = 3 -- pixel advance per frame, adjust as need for proper speed.
      on prepareFrame
      if keyPressed("126") then sprite(10).member.scrollTop \
      = sprite(10).member.scrollTop + scrollrate
      else if keyPressed("125") then sprite(10).member.scrollTop \
      = sprite(10).member.scrollTop + scrollrate
      end

      end

      I keep getting an error on the very first line, saying handler expected. I only know the most basic lingo, so I'm sure there is something very simple I am supposed to do to make this work. Thanks for any help.
        • 1. Re: scrolling text with keyboard
          Level 7
          > scrollrate = 3 -- pixel advance per frame, adjust as need for proper speed.
          > on prepareFrame
          > if keyPressed("126") then sprite(10).member.scrollTop \
          > = sprite(10).member.scrollTop + scrollrate
          > else if keyPressed("125") then sprite(10).member.scrollTop \
          > = sprite(10).member.scrollTop + scrollrate
          > end

          Unless your code is a variable declaration starting with 'global' or
          'property', it *must* go into a handler (assuming #lingo syntax).
          So:
          -- movie script:
          global gScrollRate

          on prepareMovie
          gScrollRate = 3
          end


          -- behavior script (yours with alterations):
          global gScrollRate -- inform the handlers in this script
          -- that the variable name declared here is accessible to them

          on prepareFrame me
          if keyPressed(126) then
          sprite(10).member.scrollTop = \
          sprite(10).member.scrollTop + gScrollRate
          else if keyPressed(125) then
          sprite(10).member.scrollTop = \
          sprite(10).member.scrollTop + gScrollRate
          end if
          end
          • 2. Re: scrolling text with keyboard
            morningstar Level 1
            Hi,
            Thanks so much for your help. However, I still can't get the code to work. Here is what I did -

            I put the following into a movie script:

            global gScrollRate

            on prepareMovie

            gScrollRate = 3

            end

            Then I put the following in a frame script:

            global gScrollRate -- inform the handlers in this script

            -- that the variable name declared here is accessible to them


            on prepareframe me

            if keyPressed(126) then

            sprite(10).member.scrollTop = \

            sprite(10).member.scrollTop + gScrollRate

            else if keyPressed(125) then

            sprite(10).member.scrollTop = \

            sprite(10).member.scrollTop + gScrollRate

            end if

            end

            What happened is that I got the following error message:
            Operand expected
            sprite(10).member.scrollTop = \ ?

            I also tried the script attached to the field as a begin sprite script, with the same result. It makes more sense to me to use a begin sprite rather than frame script but perhaps I'm off on that. I also wasn't sure what setting the field should be on and so I tried fixed and limited to field size. Anyway, I had sort of given up on this when it didn't work, but as I desperately need it, I'm trying again. Any further help would be greatly appreciated.
            • 3. Re: scrolling text with keyboard
              morningstar Level 1
              Hi,
              Thanks so much for your help. However, I still can't get the code to work. Here is what I did -

              I put the following into a movie script:

              global gScrollRate

              on prepareMovie

              gScrollRate = 3

              end

              Then I put the following in a frame script:

              global gScrollRate -- inform the handlers in this script

              -- that the variable name declared here is accessible to them


              on prepareframe me

              if keyPressed(126) then

              sprite(10).member.scrollTop = \

              sprite(10).member.scrollTop + gScrollRate

              else if keyPressed(125) then

              sprite(10).member.scrollTop = \

              sprite(10).member.scrollTop + gScrollRate

              end if

              end

              What happened is that I got the following error message:
              Operand expected
              sprite(10).member.scrollTop = \ ?

              I also tried the script attached to the field as a begin sprite script, with the same result. It makes more sense to me to use a begin sprite rather than frame script but perhaps I'm off on that. I also wasn't sure what setting the field should be on and so I tried fixed and limited to field size. Anyway, I had sort of given up on this when it didn't work, but as I desperately need it, I'm trying again. Any further help would be greatly appreciated.
              • 4. Re: scrolling text with keyboard
                Level 7
                On Tue, 13 Jun 2006 16:15:14 GMT, morningstar posted in
                macromedia.director.lingo:

                > What happened is that I got the following error message:
                > Operand expected
                > sprite(10).member.scrollTop = \ ?

                That's because you have blank lines following the \ line continuation
                characters. When you use that feature, you need to make sure the next line
                contains the continuing code:

                sprite(10).member.scrollTop = \
                sprite(10).member.scrollTop + gScrollRate

                Or just put it all on one line:

                sprite(10).member.scrollTop = sprite(10).member.scrollTop + gScrollRate



                --
                Mark A. Boyd
                Keep-On-Learnin' :)
                • 5. Re: scrolling text with keyboard
                  morningstar Level 1
                  Hi,
                  Thanks for your help, but nothing happened when I used script. I'm no longer getting any error messages but I'm still not able to scroll with the keyboard up and down arrows. I tried using both the fixed and limit to field size options for the field with no luck. Obviously, when I use the scrolling option I get the scroll bar, which is what I want to avoid. Any further suggestions? Again any assistance is greatly appreciated.
                  • 6. Re: scrolling text with keyboard
                    Level 7
                    On Tue, 13 Jun 2006 21:31:04 GMT, morningstar posted in
                    macromedia.director.lingo:

                    > Hi,
                    > Thanks for your help, but nothing happened when I used script. I'm no
                    > longer
                    > getting any error messages but I'm still not able to scroll with the
                    > keyboard up and down arrows. I tried using both the fixed and limit to
                    > field size options for the field with no luck. Obviously, when I use
                    > the scrolling option I get the scroll bar, which is what I want to
                    > avoid. Any further suggestions? Again any assistance is greatly
                    > appreciated.

                    Hmm. I just copied your code, removed the extra blank lines, and it worked
                    just fine for me in a simple test movie. I used a #fixed #text member.

                    (you'll want to change one of those '+ gScrollRate' to '- gScrollRate').

                    Try it in a simple test movie yourself. There's a chance that something else
                    is trapping the keys before this behavior. Do you have a behavior on the
                    sprite itself?


                    --
                    Mark A. Boyd
                    Keep-On-Learnin' :)
                    • 7. Re: scrolling text with keyboard
                      Level 7
                      On Tue, 13 Jun 2006 21:31:04 GMT, morningstar posted in
                      macromedia.director.lingo:

                      > I'm no longer
                      > getting any error messages but I'm still not able to scroll with the
                      > keyboard up and down arrows.

                      I forgot to mention. If in Authoring mode, make sure the stage has the focus.


                      --
                      Mark A. Boyd
                      Keep-On-Learnin' :)
                      • 8. Re: scrolling text with keyboard
                        morningstar Level 1
                        Hi,
                        Thanks again for the help. I figured out what the problem was. I was trying to use the script on a field text sprite. When I tried it on a text sprite it worked fine. However, I need to use keyboard arrows to scroll editable user input and have the background transparent, at the same time. Background transparent works fine with field sprites but is a bit strange with editable text spries, where the background only becomes transparent after the user clicks a different editable text sprite. So it would work much better for me if I could find a script that would scroll text with keyboard arrows in a field sprite vs. a text sprite (unless someone knows how to make the background transparent feature work better with text sprites.)

                        I can also use a flash text sprite which automatically scrolls with arrow keys and allows background transparent, but I also need the user to be able to copy portions of their input and paste it in another field sprite. I can figure out how to do this in Director, but don't know how to do this with Flash. Also want the user to be able to save their input -- again something I can do in Director -- but not sure how with flash sprites which unlike director text fields automatically erases text.

                        I am not using the text flash component that comes with Director MX2004 as I can't figure out how to make it work with multiple lines of text (though I'm sure there's some simple way to do this) but rather flash text sprites (swf movie files) that I import from Flash.

                        So to summarize, I need to have the user be able to use keyboard arrows to scroll their own text input, using the background transparent feature, and to be able to copy, paste and save sections of their input. The easiest solution would be if there was some way to using a scrolling script on field text. Thanks much for any additional suggestions.