MouseMove error

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
daryl
Posts: 47
Joined: Mon Apr 29, 2013 11:43 pm

MouseMove error

Post by daryl » Tue Apr 30, 2013 11:00 pm

Hi Folks,

I am trying to use the following code in the "Link text rollover effect" in the LiveCode Lessons How To samples:

## first unhighlight the "old" phrase if necessary:
if storedHilitedChunk is not empty and storedHilitedChunk is not overChunk then
set the backgroundColor of storedHilitedChunk to empty
put empty into storedHilitedChunk
end if

## highlight if the text under the mouse is linked:
if overChunk is not empty then
if the textStyle of overChunk is "link" then
set the backgroundColor of overChunk to "yellow"

## saved for later unhighlighting
put overChunk into storedHilitedChunk
end if
end if
pass mouseMove
end mouseMove

but I am getting the following error:

field "Server Documents" execution error at line n/a (Chunk: error in object expression near storedHilitedChunk", char 1

and have not been able to find any reference to this error.
Any help would be greatly appreciated.

Thanks,

Daryl

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: MouseMove error

Post by bn » Wed May 01, 2013 12:07 am

Hi Daryl,

use the following code in a field that you named "text" in the Properties Inspector (without quotes)

Code: Select all

local storedHilitedChunk -- here the script local variable storedHilitedChunk is declared

on mouseMove
       put the mouseChunk into overChunk
   
       ## first unhighlight the "old" phrase if necessary:
       if storedHilitedChunk is not empty and storedHilitedChunk is not overChunk then
              set the backgroundColor of storedHilitedChunk to empty
              put empty into storedHilitedChunk
       end if
   
   ## highlight if the text under the mouse is linked:
       if overChunk is not empty then
              if the textStyle of overChunk is "link" then
                     set the backgroundColor of overChunk to "yellow"
         
                     ## saved for later unhighlighting
                     put overChunk into storedHilitedChunk
              end if
       end if
       pass mouseMove 
end mouseMove

on mouseLeave
       ## unhighlight any currently highlighted text:
       if storedHilitedChunk is not empty then
              set the backgroundColor of storedHilitedChunk to empty
              put empty into storedHilitedChunk
       end if
       pass mouseLeave
end mouseLeave
You will notice that it is the same code as in the lesson EXCEPT that the lesson left out the declaration of the script local variable storedHilitedChunk. This is done on top of the script see the comment in the code in the first line.

By declaring a script local variable both handlers, the mouseMove handler and the mouseLeave handler have access to the variable storedHilitedChunk. As that was missing from the lesson it threw an error.

Now you paste or type some text into the field and use

Code: Select all

set the textStyle of word 32 of field "text" to link
either in a button or from the message box. change the number 32 to a couple of instances of words in your text and they will appear underlined. Now move the mouse over the text and the underlined link style text hilites yellow.

Kind regards
Bernd

I attach the sample stack with above code as zip file
Attachments
hiliteLInkedText.livecode.zip
(1.67 KiB) Downloaded 182 times

daryl
Posts: 47
Joined: Mon Apr 29, 2013 11:43 pm

Re: MouseMove error

Post by daryl » Wed May 01, 2013 12:27 am

Hi Bernd,

Thanks for your reply, I appreciate it. I will study it and give it a try.
This forum awesome!

Best Regards,

Daryl

Post Reply