Page 1 of 1

Displaying an image coded by a parameter

Posted: Sun Feb 28, 2016 6:22 pm
by greg falda
Hello

I have a variable

Code: Select all

tImageID
with intended integer range from 1 to 3.
I have three images stored in files, named

Code: Select all

image1.jpg, image2.jpg, image3.jpg
I have a control to display the image of my choice on my card.
Please provide a piece of code to display either image1.jpg or image2.jpg or image3.jpg acccording to the value of tImageID.
It could be one control with 3 interchangeable images or 3 controls displayed on same place - I don't care much, though the first solution seems to be more elegant.

The essence is, I just want to display (on the same place) a proper image according to the value of tImageID.

Please advise.

Best,
greg falda

Re: Displaying an image coded by a parameter

Posted: Sun Feb 28, 2016 6:31 pm
by zaxos

Code: Select all

 set the folder to "imagesFolderPath"
  switch tImageID
      case "1" then
         put URL "binfile:image1.jpg" into img 1
         break
      case "2" then
         put URL "binfile:image2.jpg" into img 1
         break
      case "3" then
         put URL "binfile:image3.jpg" into img 1
         break
   end switch
OR

Code: Select all

on mouseUp
   set the folder to "theImagesFolder"
   put URL ("binfile:image"&tImageID&".jpg") into img 1
end mouseUp

Re: Displaying an image coded by a parameter

Posted: Sun Feb 28, 2016 6:52 pm
by quailcreek
Hi Greg,
Is this for Mac, Windows, iOS...

Re: Displaying an image coded by a parameter

Posted: Sun Feb 28, 2016 7:06 pm
by dunbarx
Hi.

What Zaxos said.

But are those three images actually located in an external file? If the images are already resident in your stack, and with only three I am thinking they might be, then, just for giggles, in a button script:

Code: Select all

on mouseUp
   lock screen
         hideAll
         show img tImageID
end mouseUp

on hideAll
   repeat with y = 1 to 3
      hide img y
   end repeat
end hideAll
Anyway, just something to think about. By the way, is the variable "tImageID" a global variable?

Craig Newman