Chaiya Whangmongkollert <[EMAIL PROTECTED]> wrote:
> If i have many button .. I can't insert the next character in to the display
> textfield.
> like this .. (button1 contains character ABC,button2 contains character
> DEF,button3 contans GHI)
> 1st click on1st button ...A
> 1st click on2nd button ..AD
> 2nd click on 3rd button .. ADH
> 3rd click on next button.......
Hi Chaiya,
You're going to need two behaviors: one on the button sprites and one on the
text display sprite. The behavior on the button sprite will allow you to
define a preset list of letters using the getPropertyDescriptionList()
handler, and then simply cycle through the list of letters on each press.
The behavior on the display sprite will work out where to place the incoming
letter, and reset the last input behavior so that you can place two letters
from the same button in a row. You could use a timeOut object in the
display behavior to differenciate between closely-spaced presses on a button
- "A" no "B" no "C" - and widely-spaced presses - "A"..."AA"..."AAA".
Here's a behavior for the input button sprites It assumes that the text
display sprite is in channel 13:
-- LETTER INPUT ------------------------------------------------------------
-- PROPERTY DECLARATIONS --
property spriteNum -- channel in which this sprite appears
property letters -- string of letters this button cycles through
property pCounter -- number of letter in string used for input
property pMax -- number of letters in string
-- EVENT HANDLERS --
on beginSprite(me)
pCounter = 0
pMax = letters.char.count
end beginSprite
on mouseUp me
pCounter = (pCounter mod pMax) + 1
tLetter = letters.char[pCounter]
sendSprite(13, #mKeyPress, spriteNum, tLetter) -- HARDCODED
end
-- PUBLIC METHODS
on mReset(me) --------------------------------------------------------
-- SENT BY the mKeyPress() and the mReset() handlers of the
-- Display Input behavior on the display (sprite 13)
--------------------------------------------------------------------
pCounter = 0
end mReset
-- BEHAVIOR PARAMETERS --
on getPropertyDescriptionList(me)
tPropertyList = [:]
tPropertyList[ \
#letters] = [ \
#comment: "Letters typed in using this key", \
#format: #string, \
#range: ["ABC", "DEF", "GHI", "JKL", "MNO", "PQRS", "TUV", "WXYZ"],\
#default: "ABC" \
]
return tPropertyList
end getPropertyDescriptionList
----------------------------------------------------------------------------
And here's a behavior for the text display sprite:
-- DISPLAY INPUT -----------------------------------------------------------
-- PROPERTY DECLARATIONS --
property delay -- number of milliseconds before a button
-- switches from cycling letters to entering a
-- new letter
property pTimeOut -- timeOut object which uses the delay property
property pMember -- the text or field member of this sprite
property pLastButton -- spriteNum of the last button to input a letter
property pCharCount -- input position in text display
-- SPRITE EVENT --
on beginSprite(me)
pMember = sprite(me.spriteNum).member
pMember.text = ""
pLastButton = 0
pCharCount = 0
end beginSprite
-- PUBLIC METHODS --
on mKeyPress(me, aSpriteNum, aLetter) --------------------------------
-- SENT BY one of the Key Input instances
-- INPUT: <aSpriteNum> is the number of the input sprite that the
-- user clicked on
-- <aLetter> is the letter the user wants to input
-- ACTION: Adds <aLetter> to the appropriate place in the string
--------------------------------------------------------------------
if aSpriteNum <> pLastButton then
-- The user pressed this input button after a timeOut pause or
-- after a previously pressing a different button
-- Move on to a new character
pCharCount = pCharCount + 1
-- Reset the last button pressed so it starts from the beginning
sendSprite(pLastButton, #mReset)
-- Remember this button
pLastButton = aSpriteNum
else
-- The user has pressed the same input button twice or more in
-- quick succession
if ilk(pTimeOut) <> #timeOut then
pCharCount = pCharCount + 1
end if
end if
-- tText = pMember.text
-- put aLetter into char pCharCount of tText
-- pMember.text = tText
pMember.char[pCharCount] = aLetter
-- Allow a short pause before considering the next input from the
-- same sprite to be a new letter
me.mKillTimeOut()
pTimeOut = timeOut(string(me)).new(delay, #mReset, me)
end mKeyPress
on mBackSpace(me) ----------------------------------------------------
-- SENT BY the Backspace button
-- ACTION: Erases the last letter typed
--------------------------------------------------------------------
pMember.char[pCharCount] = ""
pCharCount = max(0, pCharCount - 1)
pLastButton = 0
me.mKillTimeOut()
end mBackSpace
on mReset(me) --------------------------------------------------------
-- SENT BY the pTimeOut object if the user pauses between button
-- presses
-- ACTION: Allows the user to press the same button twice, with a
-- pause to enter another letter from the same button
--------------------------------------------------------------------
sendSprite(pLastButton, #mReset)
me.mKillTimeOut()
end mReset
-- PRIVATE METHODS --
on mKillTimeOut(me) --------------------------------------------------
-- SENT BY mKeyPress(), mReset()
-- ACTION: Destroys pTimeOut cleanly
--------------------------------------------------------------------
if ilk(pTimeOut, #timeOut) then
pTimeOut.target = VOID
pTimeOut.forget()
pTimeOut = VOID
end if
end mKillTimeOut
-- BEHAVIOR PARAMETERS --
on getPropertyDescriptionList(me)
tPropertyList = [:]
tPropertyList[ \
#delay] = [ \
#comment: "Milliseconds to wait to input new letter from same button", \
#format: #integer, \
#range: [#min: 0, #max: 2000],\
#default: 500 \
]
return tPropertyList
end getPropertyDescriptionList
----------------------------------------------------------------------------
I'll let you work out the behavior for the Backspace button yourself.
Cheers,
James
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/lingo-l.cgi To post messages to the list, email
[EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for
learning and helping with programming Lingo. Thanks!]