arrowkey and selectionchanged in a list field

Eric Chatonet eric.chatonet at sosmartsoftware.com
Sat Jun 23 06:36:34 EDT 2007


Hi David,

Le 23 juin 07 à 12:15, David Glasgow a écrit :

> I have a list field containing the names of JPGs.  I want the  
> selected image displayed.  This is easy using mouseup or  
> selectionchanged to trigger the appropriate URL being prepended to  
> the filename, and the file displayed correctly.
>
> However, I wanted users to be able to arrow up and down through the  
> field, and the image to change just as if the selection had changed  
> by being clicked on.  Unfortunately, selectionchanged is not sent  
> if the selection  is changed via arrow keys.  This is a bit sad,  
> but documented as normal behaviour.  This means you need to catch  
> arrowkey, and then script accordingly.
>
> I was surprised to discover that the selectedline reported in this  
> way seems to lag one behind the actual selected line, and display  
> an image adjacent to the correct one.   I put the script in a group  
> containing the list field, so I expected the selection to have  
> changed by the time the message reached the group.  But it  
> doesn't.  Que pasa?
>
> I have worked around it by adding or subtracting one from the  
> reported selectedline in a switch case structure, but then had to  
> add script to test whether the tnewselectedline variable would be  
> taken out of range by the calculation.  Happy to have got it  
> working, but I can't believe there isn't a better way of doing  
> things (- isn't there always in Rev?).
>
> If the selection change by arrow key triggered the selectionchanged  
> message, my cludge wouldn't be needed at all.  What have other  
> folks done to achieve the same thing?

Here is a code snippet that might get you started.
You'll put it in the card script.

on arrowkey pKey
   if the number of lines of fld <My Field> > 2 then
     if (pKey = "up" and the hilitedLines of fld <My Field> = 1) then
       set the hilitedLines of fld <My Field> to the number of lines  
of fld <My Field>
     else if (pKey = "down" and the hilitedLines of fld <My Field> =  
the number of lines of fld <My Field>) then
       set the hilitedLines of fld <My Field> to 1
     else
       if pKey = "down" then set the hilitedLines of fld <My Field>  
to (the hilitedLines of fld <My Field> + 1)
       else set the hilitedLines of fld <My Field> to (the  
hilitedLines of fld <My Field> - 1)
     end if
     <Display Image>
   end if
end arrowkey

Note that it acts like a carousel.
Rev does not send selectionChanged when selection is changed by  
script: could bring recursion problems ;-)

Best regards from Paris,
Eric Chatonet.
----------------------------------------------------------------
Plugins and tutorials for Revolution: http://www.sosmartsoftware.com/
Email: eric.chatonet at sosmartsoftware.com/
----------------------------------------------------------------





More information about the use-livecode mailing list