Stopping actions

I’m playing around with AS Studio. I have set up a main window. In this window are two buttons (Run, Cancel). If the run button is clicked then the main window is hidden and a status window appears. The status window contains a progress indicator and a button called Stop.
Right now all I’m doing is running a repeat loop to increment the progress indicator. What I would like to be able to do is click the stop button and have action stopped (like say if I were unstuffing a file and I decided I had the wrong one or something.) However, the button in the Status window cannot be clicked (or have any keyboard actions) until the progress indicator completes its looping. So the question is how do I make the button accessible to keyboard or mouse clicks or is this something that has mainly to do with the fact that I’m just looping and not really doing anything?

Thanks

PreTech

on clicked theObject
	(*Add your script here.*)
	my theWindow(theObject)
end clicked

on awake from nib theObject
	(*Add your script here.*)
	set visible of window "Main" to false
	set visible of window "Status" to true
	my startProg()
end awake from nib

on theWindow(t)
	if title of window of t is "Main" then
		if name of t is "run" then
			load nib "Status"
		else if name of t is "cancel" then
			quit me
		end if
	else if title of window of t is "Status" then
		-- this indicates that the button "Stop" has been pressed. All action should halt.
		hide window "Status"
		show window "Main"
	end if
end theWindow

on startProg()
	if visible of window "Status" is true then
		--display dialog "v"
		set thisWindow to window "Status"
		set indeterminate of progress indicator "prog" of thisWindow to false
		tell progress indicator "prog" of thisWindow to start
		--display dialog "p"
		repeat with i from 1 to 100
			tell progress indicator "prog" of thisWindow to increment by 1
			
			delay 0.1
		end repeat
		tell progress indicator "prog" of thisWindow to stop
	end if
end startProg

P.S. How do I stop actions without quiting the app?

Model: dual 1.8 G5
AppleScript: 2.1 (80)
Browser: Safari 412.5
Operating System: Mac OS X (10.4)

Jacques,

Thanks for the reply. I would have written sooner but I was busy with the hollidays.

This is the new code I have for this little test. Instead of creating a new nib for the second window (because the new nib does not contain the “will become active” handler) I made a new window in the main nib. This seems to work alright, but maybe you can answer this question. While playing with this for several tries I have included a delay statement in the loop (so the progress bar increases slow enough for me to click the stop button). Sometimes, as in the first code, it works fine. However, in the new code it seems to stall the app. The app starts and then the opening window will recieve no button clicks or keyboard input. Why is this?

on clicked theObject
	(*Add your script here.*)
	if name of theObject is "run" then
		set visible of window "Status" to true
		set visible of window "Main" to false
	else if name of theObject is "cancel" then
		quit me
	else if name of theObject is "stop" then
		quit me
	end if
end clicked

on will become active theObject
	(*Add your script here.*)
	
	--display dialog "v"
	my startProg()
	
end will become active

on startProg()
	set indeterminate of progress indicator "prog" of window "Status" to false
	tell progress indicator "prog" of window "Status" to start
	repeat with i from 1 to 100
		tell progress indicator "prog" of window "Status" to increment by 1
		--delay 0.1
	end repeat
	tell progress indicator "prog" of window "Status" to stop
end startProg

Thanks again.

PreTech