Variable isn't being defined...

Hi all! I recently ran into a snag with my program. If I build the application, everything works nicely, but if I closed down XCode and come back later to run my App, I start getting errors that variables are not defined. It works fine from a fresh build, but only for so long.

Here is the part of my code giving me problems. (I have the “try” sections commented out so I could actually see what the error was.)

 if name of theObject is "rotateCW" then
		tell progress indicator "theSpinner" of window "mainWindow" to start
		--try
		tell application "Image Events"
			set theImage to (item currentListPosition of sourceList)
			set rotateImage to open theImage
			rotate rotateImage to angle 90
			save rotateImage
			my loadPhoto()
		end tell
		(*on error
			display dialog "Cannot rotate image. (Possible cause(s): No image selected, permission denied.))"
		end try*)
		tell progress indicator "theSpinner" of window "mainWindow" to stop
end if

This is the error that is received.

If works like a charm when doing a “build and run”… not sure what to do here.

Thanks much.

Hi,

it’s recommended to launch Image Events explicitly.
If you don’t need the image any more after rotating, close it


.
tell application "Image Events"
	launch
	set theImage to (item currentListPosition of sourceList)
	set rotateImage to open theImage
	tell rotateImage
		rotate to angle 90
		save
		close -- if the image is no longer needed, release it from memory
	end tell
	my loadPhoto()
end tell
.

Thanks. Problem solved.