|
|
|
Limited Fields
Added on 12/19/1999
|
This is a simple behavior for text and field members that does the following...
Limit a field to certain Characters, Limit a field to a certain NUMBER of characters, Turn the word wrap on/off for the field
Enhanced on 9/20/2005 by Dean Utian - fixed so backspace, and arrows work
----
-- Restrict Chars behavior covering backspace/delete/left-right arrows/return/enter/home/end
property spriteNum, maxText, allowedKeys, myWrap, otherHandler
on getPropertyDescriptionList me
p_list = [:]
p_list.addProp(#maxText, [#format : #integer, #comment : "Max number of allowed Characters:", #default : 20])
p_list.addProp(#allowedKeys, [#format : #string, #comment : "Keys to pass to field (Leave blank for all):", #default : "1234567890abcdefghijklmnopqrstuvwxyz"])
p_list.addProp(#myWrap, [#format : #boolean, #comment : "Allow word wrapping?", #default : 0])
return p_list
end
on beginSprite me
sprite(spriteNum).member.wordwrap = myWrap
end
on keyDown me
case the keyCode of
-- 51,117: -- backspace/delete
-- 115,119: left/right arrow
-- 123,124: -- home/end
-- 36: -- enter/return
51,117,123,124:
pass
36,115,119:
dontpassevent
otherwise
if allowedKeys contains the key and allowedKeys <> "" then
if sprite(me.spriteNum).member.char.count < maxText then pass
else if allowedKeys = "" then
pass
else
dontpassevent
end if
end case
on getBehaviorDescription me
describe = "This is a simple behavior for text and field members that does the following..." & return
describe = describe & "Limit a field to certain Characters" & return & "Limit a field to a certain NUMBER of characters" & "Turn the word wrap on/off for the field"
end
|
|