highlight text with button in a field
hi guys. have field1 scrollable, uneditable text, , below theres field2 user writes word found in field1. highlight works after write word in field2 , hit enter. want search work pressing button , not pressing enter key, have not been able relate button behaviors in fields.
these behaviors have related fields, or can see attached dir file:
field1
property pmemref
property pstartcolor
property philitecolor
property pwholeword
property pstatusmem
on beginsprite me
pmemref = sprite(me.spritenum).member
pstartcolor = pmemref.color
philitecolor = color(#rgb, 255, 0, 0)
pstatusmem.text = empty
me.resetmycolor()
end
on setwholewordsearch me, flag
pwholeword = flag
end
on resetmycolor me
pmemref.color = pstartcolor
end
on hiliteword me, wordsearch
if not voidp(wordsearch) then
if wordsearch <> empty then
me.resetmycolor()
tempstr = pmemref.text
hilitelist = []
counter = 0
repeat while offset(wordsearch, tempstr)
startchar = offset(wordsearch, tempstr)
endchar = startchar + wordsearch.char.count - 1
flag = true
if pwholeword then
prevchar = tempstr.char[startchar-1]
nextchar = tempstr.char[startchar+wordsearch.char.count]
charstring = "abcdefghijklmnopqrstuvwxyz"
if charstring contains prevchar or charstring contains nextchar then
flag = false
end if
end if
if flag then
hilitelist.append( [counter + startchar, counter + endchar] )
end if
delete char 1 endchar of tempstr
counter = counter + endchar
end repeat
if hilitelist.count > 0
repeat in hilitelist
pmemref.char[i[1]..i[2]].color = philitecolor
end repeat
if hilitelist.count = 1 then
pstatusmem.text = "there 1 match."
else
pstatusmem.text = "there were" && hilitelist.count && "matches."
end if
else
pstatusmem.text = "there no matches."
end if
end if
end if
end
on getpropertydescriptionlist
return [#pstatusmem: [#format: #text, #default: 0, #comment: "select status text member:"]]
end
and field2
property pmemref
property ptextsprite
on beginsprite me
pmemref = sprite(me.spritenum).member
pmemref.text = empty
end
on keydown me
if key = return then
sendsprite(ptextsprite, #hiliteword, pmemref.text)
else
pass
end if
end
on getpropertydescriptionlist
return [#ptextsprite: [#format: #integer, #default: 1, #comment: "enter text sprite number:"]]
end
here's 1 way. on field 2 behavior, add:
on hilitetext me
sendsprite(ptextsprite, #hiliteword, pmemref.text)
end
and change in keydown handler
if key = return then
sendsprite(ptextsprite, #hiliteword, pmemref.text)
else
to:
if key = return then
hilitetext(me)
else
and on button, either sendallsprites or sendsprite(<your field2 sprite>, #hilitetext)
on mouseup me
sendallsprites(#hilitetext)
end
--
mark a. boyd
keep-on-learnin' :-)
if reading via email, aware may not accurate representation of message. login read actual message and/or reply.
More discussions in Director Basics
adobe
Comments
Post a Comment