Page 1 of 1
Hiding more than one object in one command?
Posted: Sun Oct 03, 2010 4:43 am
by peter.s
Hi there,
I apologise if this is one of those "couldn't see it for its simplicity" questions, but I just can't figure it out...
How can I hide multiple objects (multiple fields and/or multiple buttons) in the fewest lines of code?
For example: I can hide a button with
Code: Select all
on mouseUp
hide button "ButtonOne"
end mouseUp
But how to do it for multiples without having a long list of code like, for example...
Code: Select all
on mouseUp
hide button "ButtonOne"
hide button "ButtonTwo"
hide button "ButtonThree"
-- etc.
end mouseUp
Cheers,
Peter
Re: Hiding more than one object in one command?
Posted: Sun Oct 03, 2010 5:33 am
by RogerK
Peter,
You could try including all the objects you want to hide in a single group, then hide or show the group.
Would that work for your particular needs?
RogerK
Re: Hiding more than one object in one command?
Posted: Sun Oct 03, 2010 6:27 am
by peter.s
Hi Roger,
Thanks for your reply - unfortunately grouping the objects won't help here.
I need different elements (objects/buttons) to be shown or hidden depending on which buttons are activated. I would imagine writing scripts to group and ungroup different collections of objects in order to hide or show them, would be much the same as simply listing each of them for each button.
I tried using square brackets, eg: ["ButtonOne" "ButtonTwo" "ButtonThree"], but that doesn't work either...
Peter
Re: Hiding more than one object in one command?
Posted: Sun Oct 03, 2010 9:32 am
by nsrev
Name the buttons as Button1, Button2, Button3 then use a loop such the following:
on mouseUp
repeat with i = 1 to 3
hide button ("button" & i)
end repeat
end mouseUp
Re: Hiding more than one object in one command?
Posted: Sun Oct 03, 2010 10:28 am
by peter.s
Thanks!
I can see the logic with this - very neat, but I would have to add something to exclude particular buttons I don't want hidden.
Out of interest... Is it recommended to use a loop like described above and not recommended to have a list (like I've described in my initial post above), which includes say 20 buttons? Or does it make little difference which way it's done?
Cheers,
Peter
Re: Hiding more than one object in one command?
Posted: Sun Oct 03, 2010 11:02 am
by Klaus
Hi Peter,
I'm afraid you will not be ab le to avoid writing a list of all button names you want to hide, if nsrev's script does not fit for you.
But you could try this:
Code: Select all
...
put "Button2,Button 666,Button 788,Another Button,an another one" into tList
repeat for each item i in tList
hide btn i
end repeat
...
Best
Klaus
Re: Hiding more than one object in one command?
Posted: Sun Oct 03, 2010 11:19 am
by RogerK
Peter,
If you have to live with the loop solution, remember to "lock screen" at the start of your script. It'll run much faster and will avoid any strange screen effects as items disappear.
Cheers
RogerK
Re: Hiding more than one object in one command?
Posted: Sun Oct 03, 2010 12:52 pm
by Regulae
Hi Peter,
I've made a small sample stack to illustrate one approach to the problem. There's a discussion field which explains how it works.
Regards,
Michael
Re: Hiding more than one object in one command?
Posted: Mon Oct 04, 2010 4:14 am
by peter.s
I must say - this forum is invaluable for beginners/dabblers like me.
A big Thank You! to everyone who contributed to this post! Each contribution has been helpful and Michael's sample stack is a neat bonus. I feel I have a lot to move forward with now...
Kind regards,
Peter
Re: Hiding more than one object in one command?
Posted: Tue Oct 05, 2010 9:03 am
by Mark
Peter,
You might want to lock the screen at the start of your script and unlock it at the end (search for lockScreen in the dictionary).
Best,
Mark