Page 1 of 1

"trapping" a hilited line change on mouse click

Posted: Tue Mar 17, 2009 11:18 am
by Atomic
Hi all,

I'm new to RR and would appreciate some help.

I have a list in a text field. When the user clicks on a line in the list, I want to action some code BEFORE the line just clicked on is hilited. ie. the flow/experience I want is:

- the currently hilited line is LineX
- user clicks on LineY
- some code is executed (LineX is still hilited)
- LineY is then hilited (or not)

I thought that this would be via mouseDown - and that I would need to pass the mouseDown message for the hilited line to change. Here's the example I have being trying to get this working:

Code: Select all

on mouseDown
   answer "Hello" -- or some other code here
end mouseDown 
However, I get the following when I test this:

- the currently hilited line is LineX
- user clicks on LineY (and does not release the mouse, so it's still down)
- LineY is hilited
- code is executed (ie "Hello")

Perhaps mouseDown is not the correct message to handle? I thought that I would have had to pass the mouseDown message for the hilted line to change?

Thanks,
Vicktor.

Posted: Tue Mar 17, 2009 12:30 pm
by gyroscope
Hi Vicktor, welcome to the Forum.

I think I'm understanding what you're after....perhaps using "the selectedLine" then putting that into a variable would get what you want? Then when the user clicks another line, put that into a second variable but the first variable is used for whatever code you need.

"Thinking out loud" here: the variables need to be globals so that you declare them first in the card script:

Code: Select all

global tLine1, tLine2
on openCard
put 0 into tLine1
put 0 into tLine2
end openCard 

Code: Select all

global tLine1, tLine2
on mouseDown
if tLine1 = 0 then
   put the selectedLine into tLine1
   delete word 1 of tLine1
put word 1 of tLine into tLine1
   ---answer tLine
else 
if tLine1>0 then
put the selectedLine into tLine2
delete word 1 of tLine2
put word 1 of tLine into tLine2
put 0 into tLine1
end mouseDown
I haven't tested the code and it's probably a bit clumsy, (+ I might have misunderstood your question!) but might get to want you want.

:)

Posted: Tue Mar 17, 2009 12:39 pm
by Mark
Hi Vicktor,

Set the autoHilite of your list field to false and make a script similar to this:

Code: Select all

on mouseDown
   put line (the hilitedLine of me) of me into glass
   if glass is empty then
      beep
      set the hilitedLine of me to 1
   else
      set the hilitedLine of me to (word 2 of the clickLine)
   end if
end mouseDown
Although this is a nonsense example, it actually works. Click on an empty line and the hilitedLine will be empty the next time. That means, when you click a second time, you will hear a beep and line 1 of the field will be selected.

Best,

Mark