Sending a message
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 919
- Joined: Wed Nov 04, 2009 11:41 am
Sending a message
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?
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?
best wishes
Skids
Skids
Re: Sending a message
Hi Simon,
I would loop through ALL objects and use a "try" structure to get rid or errors
Something like this:
Best
Klaus
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
...
Klaus
-
- Posts: 919
- Joined: Wed Nov 04, 2009 11:41 am
-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Sending a message
FWIW, if the objects in question are groups you could use the openControl or preOpenControl messages.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Sending a message
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
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
-
- Posts: 919
- Joined: Wed Nov 04, 2009 11:41 am
Re: Sending a message
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
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
best wishes
Skids
Skids