Hi All
I have the following script for a custom slider that sets its thumb position and displays the value in a label (Qtr). The slider and label are in a group.
on mouseMove
put the long id of graphic "tline" of me into CurrentLine
put the long id of graphic "thumb1" of me into Currentthumb
put the height of currentline into lheight
put item 2 of the loc of Currentthumb into tloc
put the top of currentline into ltop
put lheight-(tloc-ltop) into tunits
if the value of tunits >200 then put 200 into tunits
if the value of tunits <0 then put 0 into tunits
put the value of tunits into field "Qtr" of me
if item 2 of the mouseLoc > 250 then exit mousemove
if item 2 of the mouseLoc < 50 then exit mousemove
if intersect(Currentthumb,Currentline) and the mouse is down then set the loc of Currentthumb to item 1 of the loc of Currentline & "," & item 2 of the mouseLoc
end mouseMove
There are literally dozens of sliders and, although each slider operates independently, exactly the same code is repeated in every one.
Is there any way to share this script (or even the calculations to get the value for tunits) across all the sliders without having to copy and paste the whole script into each group? I'm thinking along the lines of a calling a subroutine in VB, but I can't seem to find anything similar in Livecode.
Regards
Terry
repeating script across multiple objects
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: repeating script across multiple objects
have a look at 'behvior' in the dictionary...
Re: repeating script across multiple objects
What Dixie said.
But read up on "the target", which is an easier way of having LC determine which object is being used, and common code can then be applied to many such objects.
Please do this. Make a new mainstack. Put three sliders and one field in it. Name the sliders "S1, "S2 and "S3"". In the card script:
on scrollbardrag
put the thumbPosition of the target && the short name of the target into fld 1
end scrollbardrag
Slide anywhere, anytime. This requires a little thought on the structure of the message hierarchy, and it is high time you experimented with this sort of thing.
Craig
But read up on "the target", which is an easier way of having LC determine which object is being used, and common code can then be applied to many such objects.
Please do this. Make a new mainstack. Put three sliders and one field in it. Name the sliders "S1, "S2 and "S3"". In the card script:
on scrollbardrag
put the thumbPosition of the target && the short name of the target into fld 1
end scrollbardrag
Slide anywhere, anytime. This requires a little thought on the structure of the message hierarchy, and it is high time you experimented with this sort of thing.
Craig
Re: repeating script across multiple objects
Thanks Dixie. Finally got it to work.
Regards
Terry
Regards
Terry