This behavior will change the font style fo selected characters in an editable field. Call using sendSprite or sendAllSprites and the fontstyle to toggle..
sendSPrite(1, #toggleStyle, #bold)
--Copyright 2000 Chuck Neal
--chuck@mediamacros.com
--If you find this code helpful, send me an e-mail and let me know. :-)
property spriteNum
on toggleStyle me, whatStyle
theSelect = sprite(spriteNum).member.selection
--fix if the selection sstarts with 0
if theSelect[1] = 0 then
if theSelect[2] <= 0 then
exit
else
theSelect[1] = 1
end if
end if
if theSelect[1] = theSelect[2] then
--nothing selected
exit
end if
currentStyle = sprite(spriteNum).member.char[(theSelect[1] + 1)..theSelect[2]].fontstyle
if currentStyle.getOne(#plain) <> 0 then
currentStyle = []
end if
if whatStyle = #plain then
currentStyle = [#plain]
else
if currentStyle.getOne(whatStyle) <> 0 then
--already there, remove it
currentStyle.deleteOne(whatStyle)
else
currentStyle.add(whatStyle)
end if
end if
sprite(spriteNum).member.char[(theSelect[1] + 1)..theSelect[2]].fontstyle = currentStyle
end
on getBehaviorDescription me
describe = "Drop this on an editable text sprite to allow toggling of #bold, #italic, #plain, and #underline."
describe = describe & return & "Call like this..." & return & "sendSprite(1, #toggleStyle, #bold)"
return describe
end
Contact
MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA