Page 1 of 1
Naming buttons in a group from a list in a field
Posted: Wed Feb 07, 2007 2:51 pm
by quailcreek
Hello,
I'm new to the list. Right now I only have a demo version of RR U3 but I am impressed. I've got an app that I've been working on in another scripting package and I'd like to see what it would take to convert to RR. So my question is: How would I, on a simple mouseUp from a button, name the buttons in a group from a list in a field? And, is the order of the buttons controlled by the layer their on? I would be grateful for the assistance.
Regards
Tom
Posted: Wed Feb 07, 2007 4:08 pm
by malte
Hi Tom,
there are many ways to reference controls in revolution. Using the layer is one option.
in your button:
Code: Select all
on mouseUp
repeat with i=1 to the number of lines of field "myListField"
if there is a button i of group "myGroup" then
set the name of button i of group "myGroup" to line i of field "myListField
end if
end repeat
end mouseUp
Please feel free to ask if there are more questions.
All the best,
Malte
Posted: Wed Feb 07, 2007 9:37 pm
by quailcreek
Thanks Malte,
The script worked great. Now the next step. The buttons were named in the order of the layer they were on. Unfortunatly that's not the order I need them to be it. I want the order to be from top left to bottom right. There are three coulmns of 10 buttons in the group. Do the layers of the buttons need to be set or is there a way to control the order otherwise? I'm assuming that setting the layer order will involve a very similar repeat script. But how?
Thansk again
Tom
Posted: Thu Feb 08, 2007 1:11 am
by Mark
Hi Tom,
You probably need something like this:
Code: Select all
on setLayers
repeat with x = 1 to number of buttons
if there is a btn x of grp "MyGroup" then
put x & comma & (item 1 of the loc of btn x of grp "MyGroup") & "." & ¬
(item 2 of the loc of btn x of grp "MyGroup") & cr after myList
end if
end repeat
sort lines of myList numeric by item 2 of each
put 0 into x
repeat for each line myBtn in myList
add 1 to x
set the layer of btn (item 1 of myBtn) of grp "MyGroup" to x
end repeat
end setLayers
To use this script, your 30 buttons have to be placed exactly in the right location, i.e. the x-values of the locations of all buttons on a row have to be equal and the y-values of the locations of all buttons in a columns have to be equal too.
Best,
Mark
Posted: Thu Feb 08, 2007 2:03 am
by quailcreek
Thanks a lot Mark. I see the logic. The script works pretty well exept it goes from top right to bottom left. I need TL to BR. What do I need to change in the script?
Thanks Again
Tom
Posted: Thu Feb 08, 2007 12:39 pm
by Mark
Hi Tom,
It took a little effort, but it was a fun puzzle. Here is a scipt that sets layer numbers, starting at topleft and finishing at bottomright, either horizontally or vertically.
Code: Select all
on setLayers theGroup,theHVFlag
if theGroup is not a number then put the id of grp theGroup into theGroup
lock screen
if char 1 of theHVFlag is "h" then put "21" into myHVFlag else put "12" into myHVFlag
start editing grp id theGroup
repeat with x = 1 to number of buttons
put the id of btn x & comma & (item (char 1 of myHVFlag) of the loc of btn x)*1 & "." & ¬
format("%03d",(item (char 2 of myHVFlag) of the loc of btn x)) & cr after myList
end repeat
sort lines of myList numeric by item 2 of each
put 0 into x
repeat for each line myBtn in myList
add 1 to x
set the layer of btn id (item 1 of myBtn) to x
set the label of btn id (item 1 of myBtn) to x
end repeat
set the editbackground to false
unlock screen
end setLayers
usage:
setLayers <group name|group ID>,<"h"|"v">
examples:
setLayers "My Group","h"
setLayers 1010,"v"
Enjoy,
Mark
Posted: Thu Feb 08, 2007 2:45 pm
by quailcreek
Mark,
Awesome! Flawless! This is something I could not do in the other scripting software. If you like puzzles, I can keep you busy for quit awhile.
Regards
Tom