Custom Text Window

Date:    Thu, 20 Apr 1995 12:09:16 EDT
From:    John Dowdell <71333.42@COMPUSERVE.COM>
Subject: Re: Custom Text Window
(Q) I'd like to make my own style of scrolling textfields, with my own buttons, and be able to track which line is scrolled and more. How?

(A) Suppose there's a field displayed on Stage (called "display field") of a certain number of lines. There are two scroll buttons next to it. When the buttons are pressed, then the field appears to scroll up or down, receiving its text from a long field offstage in the Cast named, say, "source field". If the following two handlers are available in your Movie Script (or, if you've got too many handlers there already, in your button script itself), then the scroll buttons could simply say:

  
on mouseDown
    Scroll "source field", "display field", 1   --  or -1 for reverse scrolls
  end mouseDown

Here are the routines that this button calls:

  on Scroll source, display, incr
    set pos = LineOffset(source, display)
    set size = the number of lines of field display - 1
    set theMax = the number of lines of field source - size
    set chan = the clickOn
    repeat while the stillDown
      if rollover(chan) then
        set the foreColor of sprite chan = 247
        if min(max(pos + incr, 1), theMax - size) = pos + incr then
          --  that last line was essentially "if a<b AND b<c", a range test
          set pos = pos + incr
          put line pos to pos + size of field source into field display
        end if
      else
        set the foreColor of sprite chan = 255
      end if
      updateStage
    end repeat
  end Scroll

  on LineOffset source, display
    repeat with i = 1 to the number of lines in field source
      if line i of field source = line 1 of field display then return i
    end repeat
    return 0
  end LineOffset