cca@pur-phy (Charles C. Allen) (09/23/88)
In article <1455@pur-phy> cca@pur-phy (Charles C. Allen) writes: >That's easy (right, Dan? :-). Now how about sharing scripts between >different cards/fields/buttons/whatever? Having to update N different >scripts (all the same) can be painful at times, besides being wasteful >of space. In article <17539@apple.Apple.COM>, dan@Apple.COM (Dan Allen) responds: > Why do you have N different copies of the same script? If it is really > the same, then it should be in some shared location like the stack > script and thus used by all cards, fields, buttons, etc. Well, yes and no. I don't want to share the script among ALL buttons, just a select few. Let's take as an example a radio cluster. We can have the card/background look at the id or name of the target on a mouseUp and then call an appropriate handler. -- In the card or background script. -- The setClusterValue script is also in this script. on mouseUp put the short name of the target into shortName if word 1 of shortName = "background" and -+ word 2 of shortName = "button" then if char 1 of word 3 of shortName = "x" then setClusterValueViaClick end if end if end mouseUp This requires hardcoding button ID's or numbers, or some sort of sentinel in the name that the programmer has to keep track of. The advantage is that the buttons have no script. Another method is to have each button send the appropriate message. -- In the button script of all the buttons in the cluster. -- The setClusterValue handler is in the card/background script. on mouseUp setClusterValueViaClick end mouseUp This certainly seems cleaner to me, but requires that all the buttons have the same script (the reason for the original posting). A slight variation is to put the setClusterValue handler in a hidden field or button. Sometimes the card/background doesn't seem the appropriate place for things like this. In general, the inheritance hierarchy can be restrictive at times (just to be ornery and bring up something off the original subject). Naturally, I won't be happy 'til HyperTalk has all the power of Smalltalk :-). Say, any news on the Mac-ized Apple version of Smalltalk? Charlie Allen cca@newton.physics.purdue.edu