Page 1 of 1
Using "onpreOpen"
Posted: Mon May 26, 2008 3:00 am
by bjb007
I have some code which sets up a lot
of info in arrays etc which I want to run
only once when the app. starts.
At the moment it's on the main card
so runs each time a button is clicked
and I can't find anywhere to put it so
that it only runs once.
Read about "onpreOpen" and "on preOpen card"
but confused about its use.
Any clarification appreciated.
Posted: Mon May 26, 2008 5:42 am
by Janschenkel
The 'definitive' run-only-once message is 'startup'- but this will only get sent to your standalone application, never in the IDE.
So we had better find another message. I tend to put this initialization code into the 'preOpenStack' handler of the first card of my main stack, and I'll usually throw in a quick check to see if everything was initialized yet or not.
Code: Select all
on preOpenStack
global gSettingsArray
if the keys of gSettingsArray is empty then
put the seconds into gSettingsArray’"startupTime"]
...
end if
end preOpenStack
Hope this helped,
Jan Schenkel.
preOpenStack
Posted: Mon May 26, 2008 6:00 am
by bjb007
Jan
What would I do without you?
I did think of using a variable to check if
the code had been run already.
I tried using the "preOpenStack" method but
found the disadvantage was that to debug
it the stack had to be closed then re-opened.
Rather annoying I found, so I think your suggested
method is better.
Posted: Mon May 26, 2008 11:53 am
by Janschenkel
You can also trigger events yourself - in this case, you would go to the first card iof your main stack, and then open the Message Box, type in
and hit return.
If thye handler requires parameters, you can add them in the message box, just like you would call the handler from a piece of script.
Hope this helped,
Jan Schenkel.