Displaying an image coded by a parameter

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
greg falda
Posts: 77
Joined: Thu Jan 15, 2015 6:51 pm

Displaying an image coded by a parameter

Post by greg falda » Sun Feb 28, 2016 6:22 pm

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

zaxos
Posts: 222
Joined: Thu May 23, 2013 11:15 pm

Re: Displaying an image coded by a parameter

Post by zaxos » Sun Feb 28, 2016 6:31 pm

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
Knowledge is meant to be shared.

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm

Re: Displaying an image coded by a parameter

Post by quailcreek » Sun Feb 28, 2016 6:52 pm

Hi Greg,
Is this for Mac, Windows, iOS...
Tom
MacBook Pro OS Mojave 10.14

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10324
Joined: Wed May 06, 2009 2:28 pm

Re: Displaying an image coded by a parameter

Post by dunbarx » Sun Feb 28, 2016 7:06 pm

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

Post Reply