Load Image vs Load sound

OK, here’s a weird-ity. I’m working on a simple game, and it uses sounds and graphics. I’ve gotten along fine with the sounds by using a property to store the sound reference from

set explodeSnd to load sound "explode"

and put it in my awake from nib handler so I don’t have to keep loading the same sound and then disposing of it. Later, in the game, I just use

play explodeSnd

and everthing works.

However, I’ve discovered that the load image command won’t work that way (at least it’s not working for me). I’ve got the global property saving the image reference in the awake from nib handler like this:

set screen1Img to load image "nebula.jpeg"

but when I try to call it later like this:

set image of image view "viewScreen" to screen1Img

I get a “Can’t Create Script” error. I had to go back to this usage:

set image of image view "viewScreen" to load image "nebula.jpeg"

to make it work.

So, my question is, am I using memory to reload these images? Or when I load the exact same image 6 times during the course of a game, does it overlay in the same memory space?

(…and, if the handle reference works for sounds, why doesn’t it work for images? The sound definition in the Terminology guide even points to the load image page to explain how it works.:/)

Model: iMac DV+
AppleScript: 1.9.1
Browser: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.0.1) Gecko/20060214 Camino/1.0
Operating System: Mac OS X (10.2.x)

Hi Nitewing,

Loading the image in the ‘awake from nib’ handler worked for me (using OS 10.2.8).

global basso_snd, the_image

on idle theObject
play basso_snd
return 2
end idle

on awake from nib theObject
set basso_snd to load sound “Basso”
set the_image to load image “birds”
end awake from nib

on will quit theObject
delete basso_snd
end will quit

on clicked theObject
set image of image view “image” of window “main” to the_image
end clicked

Just to say that it does work, here. I don’t know why yours isn’t.

gl,

Hmmmm…:confused:

Looks to me like mine should work. I’ll double-check my code and see if there is some other thing that’s preventing it from working.

Thanks for the info!