But I can't set level of a btn with this code:
set the layer of btn "x1" to 101
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
set the layer of btn "x1" to 101
Code: Select all
on mouseUp
set the layer of btn 2 to 1 -- or "top" or bottom"
put the layer of btn 1 & return & the layer of btn 2
end mouseUp
That is exactly what the "layer" property is intended to do. Note carefully, though, that the layer refers to all controls, not just buttons, so that if you have a bunch of fields on the card, say, those are interspersed along with those hundred-odd buttons. If you want to order only the buttons themselves, you need to manage that carefully.My reason for using "set the level of btn to #" is to move an arrangement of 117 buttons to same level.
They are now scattered at great difference of depth. Perhaps it doesn't matter.
Code: Select all
on mouseUp
set the layer of btn "Button_2" to 1
put the layer of btn "Button_1" & return & the layer of btn "Button_2"
end mouseUp
Code: Select all
on mouseUp
-- level matrix of bans test
-- buttons are named x1, x2, x3...etc.
repeat with i=1 down to 117
set the layer of btn ("x"&i) to 6000
end repeat
end mouseUp
Code: Select all
-- Sorting N buttons ("x"&i) descending to bottom
repeat with i=1 to N
set layer of btn ("x"&i) to "bottom"
end repeat
-- gives, listed bottomUp: xn, ..., x2, x1
Code: Select all
--Sorting N buttons ("x"&i) ascending to top
repeat with i=1 to N
set layer of btn ("x"&i) to "top"
end repeat
--gives, listed bottomUp: x1, x2, ..., xn
Code: Select all
Advanced.
-- Sorting N buttons ("x"&i) descending (for 'ascending' similar)
-- without changing the layer of other controls # <--------
-- At first get the 'slots' of the buttons within all controls
repeat with i=1 to N
put cr & the layer of btn ("x"&i) after lst
end repeat
delete char 1 of lst
-- sort the old 'slot' numbers
sort lst descending numeric # <-- new sort order, here descending
-- put the objects one after the other in the old 'slots'
repeat with i=1 to N
set layer of btn ("x"&i) to line i of lst
end repeat
Code: Select all
on mouseUp
repeat with x = 1 to 117
put the short name of btn ("x"&x) into nm
set the layer of btn nm to x
end repeat
end mouseUp