Hide - Show Window

Hi Folks,

in my application I have a funny situation:

I have a “splash” window which should appear when the application is starting, and
should be hidden when everything is loaded…

When I put the code in the on awake from nib then everything is working fine - unless the script is delaying for 10 seconds, and everything I want to load will load afterwards…



show window id 2
delay 10
hide window id 2


so I thought it would be better to put the show and the hide in the handler on launched the Application


on launched theApplication
show window id 2

--do lots of things...

--more things...

--end reached...

hide window id 2


Now I got an “NsREcieverEvauationScriptError: 4 (1)” which means something like “file not found” - does anybody can tell me why?

Thanks for your help and support!

Stefan

If your app genuinely takes a long time to load, using a splash window can be done fairly easily. The first handler you can use to show a window is the awake from nib handler. You shouldn’t put calls to objects in any handler that is called sooner, because the objects haven’t yet been instantiated… so they technically don’t exist yet. See this apple doc for the order in which launch-time handlers are called. Also, make sure to use the awake from nib handler of the window, and not of the app, because the window is not necessarily instantiated when the app’s handler is called.

My first guess as to why your code isn’t working is that you’re referencing your window by ID??? Referencing a window by it’s ID is even more ridiculous than referencing it by it’s index. Every object has an applescript name… USE IT. ID’s are assigned by the window server, and are not usually ever 1, 2, 3, etc. Their indexes may be, but why hope that your windows are in the right order when you try to access them programmatically? Just assign each a unique name, end then reference them by that name, or by a reference stored in a persistent variable in your code. There are few occasions when using an object’s index or ID to reference it is smart.

Another thing to make sure of, is to set the “visible at launch time” of the window to unchecked. If this is set to checked, then the window opens at launch time, and may not necessarily be shown when you want it to. If you’re programamtically opening windows at startup, this should always be unchecked.

Here’s a simple setup that I might employ…

on awake from nib theObject
	if name of theObject is "splashWindow" then --> Connected to your splash window
		show window "splashWindow"
	end if
end awake from nib

on launched theObject
	(* Do your startup stuff *)
	hide window "splashWindow"
end

j

Hi Jobu,

thanks for your help - unfortuanly when using your code I get an error…


on awake from nib theObject
   if name of theObject is "splashWindow" then --> Connected to your splash window
       show window "splashWindow"
   end if
end awake from nib

I tried then:


on Idle theObject
show window "startup"
delay 10
hide window "startup"

This is working as I have expected…


on launched theApplication

hide window "startup"

will show an applescript -4 error…

Thanks for your help and best regards,

Stefan