From Director Online Wiki
Jump to: navigation, search

For Field and Text members, the .scrollTop property contains the number of pixels hidden above the top of the visible sprite display.

Bug (D7 - D10.1)

In all versions of Director from 7 (when #text members where introduced) to 10.1, Text members with a height of 16384 (16 * 1024) or more suffer from the following bug:

Text members with more than 16383 lines of text scroll in steps of a power of two, and the value of the scrollTop indicates the number of steps (not the number of pixels) from the top.

Director's built-in scroll bars will allow you to scroll such a long text member, but the scroll thumb will be wrongly placed. You will need to create your own custom scroll bars, and adjust their behavior to take into this bug into account.


Here is a comprehensive handler that allows you to the number of pixels that will be scrolled for each unit used by the .scrollTop property. It is designed to be forward-compatible, so that your movies will not break if Macromedia fix this bug in the future.

 on GetScrollRatio(aMember) --------------------------------------------
  -- INPUT: <aMember>should be a text member
  -- OUTPUT: Returns the number of pixels hidden above the top of the
  --         visible section of the text member.  A bug in text
  --         members in Director 7.0 through DMX 2004 returns the
  --         wrong value for .scrollTop if the height of the member is
  --         greater than 16383 pixels.  This handler works around
  --         that bug, and allows for the possibility that the bug
  --         will have been fixed in later versions of Director.
  if ilk(aMember) <> #member then
    return 1
  else if aMember.type <> #text then
    return 1
  end if
  vHeight = aMember.height
  if vHeight < 16384 then
    return 1
  end if
 -- If we get here, we are dealing with a text member whose height is
  -- greater than 16383.  Set the scrollTop of the member to its
  -- maximum, then determine whether it reached that value.
  vScrollTop        = aMember.scrollTop
  vHeight           = vHeight - aMember.pageHeight
  aMember.scrollTop = vHeight
  vRatio            = vHeight / aMember.scrollTop
  aMember.scrollTop = vScrollTop
  return vRatio
end GetScrollRatio


Here are a couple of simple handlers that you can use in association with your custom scroll bar behavior. They include no error checking, so you need to be sure that the input arguments are of the correct type.

on SetScroll(aMember, aScrollTop)
  vRatio = GetScrollRatio(aMember)
 vAdjustedScroll = aScrollTop / vRatio
  aMember.scrollTop = vAdjustedScroll
  return aMember.scrollTop
end SetScroll

on GetScroll(aMember)
  vRatio          = GetScrollRatio(aMember)
  vAdjustedScroll = aMember.scrollTop * vRatio
  return vAdjustedScroll
end GetScroll