Page 1 of 1
Sending a message
Posted: Tue Sep 28, 2010 2:47 pm
by Simon Knight
I am building an application that is going to use a number of different control types all with the same behavior script. One of the scripts in the behavior script will be "initialise". How would you recommend I approach the problem of sending the "initialise" message to only those controls that use the behavior script. My initial thoughts are:
1) Use a manual list : simple but a bit of a kludge, I'd rather do better.
2) Look through all the controls on the UI stack and send the message to ones that meet a criteria. I suppose my question is what criteria? For example is it possible to select objects based on the name of their associated behavior button? Should I use a custom property in each control.
Any thoughts?
Re: Sending a message
Posted: Tue Sep 28, 2010 3:02 pm
by Klaus
Hi Simon,
I would loop through ALL objects and use a "try" structure to get rid or errors
Something like this:
Code: Select all
...
repeat with i = 1 to the num of controls ## of cd x of stack y
try
send "intitialize" to control i ## of ...
## Or use "dispatch", see the docs
catch errornum
## Do nothing on error!
end try
end repeat
...
Best
Klaus
Re: Sending a message
Posted: Tue Sep 28, 2010 3:24 pm
by Simon Knight
Thanks Klaus,
I will give it a go.
Re: Sending a message
Posted: Tue Sep 28, 2010 3:40 pm
by FourthWorld
FWIW, if the objects in question are groups you could use the openControl or preOpenControl messages.
Re: Sending a message
Posted: Tue Sep 28, 2010 9:20 pm
by dunbarx
Hi.
You already answered your question. The criterion you could use is the behavior property itself, which takes the form of a long ID.
So loop through all the controls, and send the message if the behavior of the control is the long ID of the button containing the initialize script:
repeat with y = 1 to the number of controls
if the behavior of control y = yourLongID then send "initialize" to control y
end repeat
Craig Newman
Re: Sending a message
Posted: Wed Sep 29, 2010 8:14 am
by Simon Knight
Thanks Craig,
I thought it must be possible but I didn't know what the syntax would be.
A supplementary question: I am using a splash stack and this will be the stack that is compiled. The objects that need to receive the "initialise" message are on other stacks. I would like to have the initialise message sent when the user opens the application so I was wondering at what point are the other stacks available for use or to put it another way will I be able to issue the initialise message from the open stack handler of my splash stack?
Simon