PDA

View Full Version : Inconsistent Error -1700 in AppleScript Xcode App


fpbspades
07-06-2010, 11:23 PM
I'm trying to understand how to use Applescript to command NSImageview objects, specifically to load images into them. I'm using Xcode 3.1.4 on OSX 10.5.8 .

I'm working off of the "Image" Example from the Applescript Studio example programs. When I build the program it functions normally. But when I try to expand the code in Application.applescript from

on awake from nib theObject
set image of image view "image" of window "main" to load image "AboutBox"
end awake from nib

to my own code (where "s1", "s2", etc are the names of image files that I have added to the Resources folder of my project):

on awake from nib theObject
set dummyvariable to some item of {"s1", " s2", "s3", "s4"}
set image of image view "image" of window "main" to load image dummyvariable
end awake from nib

sometimes when I hit build and go, the image loads and everything is fine but other times (about one in three), but more consistently if I dont rebuild it but just run the program, I get an error:

AppleScript Error
Can't make current application into type <<class imaA>>. (-1700)


So, what could be causing this error (that only happens sometimes) and what would be a fix?

Also, I am curious what is <<class imaA>> (and for that matter <<class imaV>>, I got a -1700 error saying i couldn't make one class into the other, etc. in other attempts to get NSImageview objects to load image files)? My internet searching didn't come up with anything helpful about those classes.

FYI: I'm trying to teach myself coding with this project, so any and all help is appreciated. Thanks very much.

-fpbspades

regulus6633
07-07-2010, 03:46 AM
Here's my guess. In the "awake from nib" handler you get notified as objects get loaded from the nib file, and that handler is called each time an object is loaded. However you can't control their load order. As such when the handler is called it may have been called when a different object (other than the image view) has been loaded and thus you're trying to set the image to the image view before the image view has been loaded. There's a simple fix for that. You need an if statement to make sure which object has just been loaded. Also I would put () around the load image message to make sure that happens first before you try to set the image. Try this...
on awake from nib theObject
if theObject is image view "image" of window "main" then
set dummyvariable to some item of {"s1", " s2", "s3", "s4"}
set image of theObject to (load image dummyvariable)
end
end awake from nib