- No need for extra images
- No need for extra fonts
works out of the box with livecode even selected text can be erased properly, just put the code inside a field and its ready.
Code: Select all
local tChar,tNumber,buffer
on textChanged
set the lockText of me to false
repeat for each char theChar in me
if theChar is "*" then
-- do nothing
else
add 1 to tNumber
put theChar after tChar
end if
end repeat
replace return with "" in tChar
if buffer is an integer then
if buffer > tNumber then
delete last char of theChar
end if
end if
put tNumber into buffer
repeat for each char theChar in tChar
put "*" after theAsterisk
end repeat
put theAsterisk into me
put "X" after me
delete last char of me
--put tChar -- Uncoment this to see the text inside the field
end textChanged
on backSpaceKey
if the selectedText <> empty then
put the charIndex of the selectedText into theCharIndex
repeat for each char theChar in the selectedText
add 1 to theChars
end repeat
repeat for theChars
delete char theCharIndex in tChar
end repeat
else
delete last char in tChar
end if
textChanged
end backSpaceKey
on deleteKey
delete first char in tChar
textChanged
end deleteKey
on rawKeyDown theKey
if theKey is not 65288 then
if the selectedText <> empty then
put the charIndex of the selectedText into theCharIndex
repeat for each char theChar in the selectedText
add 1 to theChars
end repeat
repeat for theChars
delete char theCharIndex in tChar
end repeat
put numToChar(theKey) before char theCharIndex of tChar
repeat for each char theChar in tChar
put "*" after theAsterisk
end repeat
put theAsterisk into me
else
pass rawKeyDown
end if
else
pass rawKeyDown
end if
end rawKeyDown