Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
Wait for a DirectMedia CuePoint(Name as Reference)
Progress Bar
Icon Forge
Get System Time
Put stream percentage
KKT Interactive
Evil Mouse Puddle
Director Developer Hosting
XML Socket Server for Flash, Director and Authorware
Macromedia
 

 

 

Behavior auto scrolling entryfield

Added on 5/22/2002

 

Compatibilities:
D8_5

This item has not yet been rated

Author: greatbustards

this behavior limits the text of an entry field to a user defined width, and scrolls while you type and/or edit. complete entered text is property pText.

property pPosition -- current cursorposition in complete text
property ptext -- contains the complete text
property pmember -- ref to member
property spritenum
property pFirstChar -- position of first character in visible text
property pLastChar -- position of last character in visible text
property pRestrain -- show pRestrain characters
property pMax -- max number of allowed characters. 0 is unlimited characters

on beginSprite me
  pmember = sprite(spritenum).member
  reset()
  sprite(spritenum).editable = true
end

on reset me
  -- reset all props
  pMember.text = ""
  pText = ""
  the selstart = 0
  the selend = 0
  pPosition = 0
  pFirstChar = pPosition + 1
  pLastChar = pFirstChar + pRestrain - 1
end

on keydown me
  thekey = the keypressed
  -- parse input  
  case the keycode of
    36: -- enter
      cursor 4
      popresults(true)      
      finddata(pText)      
    51: -- backspace
      -- check if part of text is selected
      if the selend <> the selstart then
        delete pText.char[the selstart+ (pfirstchar - 1) + 1..the selend+ (pfirstchar - 1)]
        the selend = the selstart
        pPosition = the selstart + (pfirstchar - 1)
        showtext() -- update visible text
      else
        -- just one character
        if pPosition>0 then
          pPosition = the selstart + (pfirstchar - 1)
          pPosition = Pposition - 1
          delete pText.char[pPosition+1]
          toLeft() -- scroll to the left
          showText() -- update visible text
          -- set cursor
          the selStart = pPosition - (pfirstchar-1)
          the selEnd = the selStart
        end if
      end if      
    127: -- delete      
      -- check if part of text is selected
      if the selend <> the selstart then
        delete pText.char[the selstart+ (pfirstchar - 1) + 1..the selend+ (pfirstchar - 1)]
        the selend = the selstart
        pPosition = the selstart + (pfirstchar - 1)
        showtext()  -- update visible text
      else
        -- just one character
        if pPosition          pPosition = the selstart + (pfirstchar - 1)
          delete pText.char[pPosition+1]
          showText()  -- update visible text  
          -- set cursor
          the selStart = pPosition - (pfirstchar-1)
          the selEnd = the selStart
        end if
      end if
    123 : -- cursor left
      pPosition = the selstart + (pfirstchar-1)
      pPosition = pPosition - 1
      if pPosition < 0 then pPosition = 0      
      if the selEnd = 0 then
        toLeft() -- scrollleft
        showText() -- and update visible text
      end if
      -- set cursor
      the selStart = pPosition - (pfirstchar-1)
      the selEnd = the selStart    
    124 : -- cursor right      
      pPosition = the selstart + (pfirstchar - 1)
      pPosition = pPosition + 1
      if pPosition>pText.length then pPosition = pText.length      
      if the selEnd = pRestrain then
        toRight() -- scroll right
        showText() -- and update visible text
      end if
      -- set cursor
      the selStart = pPosition - (pfirstchar - 1)
      the selEnd = the selStart  
    otherwise
      -- all other keys
      if pText.length <= pMax or pMax = 0 then
        -- checkinput
        if "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0123456789" contains theKey then
          -- insert text at pPosition
          pPosition = the selStart + pFirstChar-1
          pPosition = pPosition + 1      
          -- set text
          put theKey before pText.char[pPosition]
          -- scroll right if needed
          if the selEnd = pRestrain then
            toRight()
          end if
          -- update visible text
          showtext()      
          -- set pointer
          the selstart = pPosition - pfirstchar + 1
          the selend = the selstart
        end if
      end if      
  end case  
end

on showtext me
  pMember.text = chars(ptext,pFirstChar,pLastChar)
end

on toRight me
  pFirstChar = pFirstChar + 1
  pLastChar = pFirstChar + pRestrain - 1
end

on toLeft me
  pFirstChar = pFirstChar - 1
  if pFirstChar < 1 then pFirstChar = 1
  pLastChar = pFirstChar + pRestrain - 1
end

on getPropertyDescriptionList
  description = [:]
  addProp description,#pRestrain, [#default:8, #format:#integer, #comment:"field width"]  
  addProp description,#pMax, [#default:0, #format:#integer, #comment:"max length. 0:unlimited"]
  return description
end

on getBehaviorDescription
    return "horizontal scroll text entered in entryfield. prop pSprite contains complete text"
end

 


Contact

MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA

Send e-mail