Page 1 of 1

Creating an image

Posted: Thu Oct 22, 2009 12:00 pm
by exheusden
I'm trying to create an image on a card. The image is one selected earlier by the user; its pathname is in the variable originalFile.

Here's the script that I would hope would create the image:
create invisible image "Original label"
put it into originalImage
set the width of originalImage to 230
set the height of originalImage to 230
set the location of originalImage to 772,319
set the fileName of originalImage to originalFile
set the visible of originalImage to true
After running this, however, the size and location of the image is that of the selected file "originalFile"; in other words, the "set the width" and "set the height" commands have had no effect (this can be seen not only in the image itself, but also in the Size & Position property panel for the image). The "set the location" and "set the fileName" commands are correctly executed.

What am I doing wrong?

Posted: Thu Oct 22, 2009 1:29 pm
by Mark
exheusden,

This should work:

Code: Select all

create invisible image "Original label"
put it into originalImage
set the fileName of originalImage to originalFile
set the width of originalImage to 230
set the height of originalImage to 230
set the location of originalImage to 772,319
set the lockLoc of originalImage to true
set the visible of originalImage to true
Best,

Mark

Posted: Thu Oct 22, 2009 1:54 pm
by exheusden
Thank you!

So, if I understand it correctly, it's the sequence of the set commands that is the key. I've tried the code by just moving the set fileName command to the top (as in your suggestion) and without the set lockLoc command (in my case, unnecessary, but I can see why you'd use it), and it works. So what is so special about the sequence of set commands? Is this documented?

Edit: Oops, spoke too soon. Looks as if the lockLoc is required. When I move to the next card and back again, the image is resized without it.

Posted: Thu Oct 22, 2009 2:03 pm
by Mark
You got it :-)

Mark

Posted: Thu Oct 22, 2009 2:03 pm
by bn
exheusden,

the problem is that if you load an image by setting the filename the image adjusts its size to the size of the referenced image except if you set the lockloc to true as Mark did.
The only difference in the order of commands is that you load the filename image first and then set the width and size, so in that case the lockloc is not necessary.
regards
Bernd

Posted: Thu Oct 22, 2009 2:09 pm
by exheusden
Okay, understand the logic. Thanks to the two of you.