5 Replies Latest reply on Jun 3, 2009 10:58 AM by Mark A. Boyd

    highlight text with button in a field

    jcsp2001 Level 1

      Hi guys. I have field1 with scrollable, uneditable text, and below theres field2 where the user writes a word that is to be found in field1. The highlight works after i write the word in field2 and hit enter. I want the search to work by pressing a button and not by pressing the enter key, but I have not been able to relate the button to the behaviors in the fields.

       

      These are the behaviors I have related to the fields, or you can see the 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 to endChar of tempStr
              counter = counter + endChar
             
            end repeat
           
            if hiliteList.count > 0 then
              repeat with i in hiliteList
                pMemRef.char[i[1]..i[2]].color = pHiliteColor
              end repeat
              if hiliteList.count = 1 then
                pStatusMem.text = "There was 1 match."       
              else
                pStatusMem.text = "There were" && hiliteList.count && "matches."
              end if
            else
              pStatusMem.text = "There were 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 the 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