Controlling an image based upon combo box selection

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: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

Post Reply
tm1274
Posts: 11
Joined: Sun Nov 12, 2006 8:20 pm

Controlling an image based upon combo box selection

Post by tm1274 » Mon Nov 13, 2006 5:23 pm

I am a newbie to Revolution and was wandering, is it possible to control an image with a selection in a combo box? Basically can a user select something in a combo box and the image change to show the picture?

Bernard
Posts: 184
Joined: Sat Apr 08, 2006 10:14 pm
Location: London, England

simple example

Post by Bernard » Mon Nov 13, 2006 5:38 pm

assuming you have a card with an image object called "my image object" and a combo box with this in the script of the combo box:

on menuPick theItem
switch theItem
case "austria"
set the filename of image "my image object" to "/Library/Application Support/Apple/iChat Icons/Flags/Austria.gif"
break
case "australia"
set the filename of image "my image object" to "/Library/Application Support/Apple/iChat Icons/Flags/Australia.gif"
break
default
end switch
end menuPick

You will see the image change (I'm using an example with 2 of the standard images that come with iChat on OS X).

Bernard
Posts: 184
Joined: Sat Apr 08, 2006 10:14 pm
Location: London, England

forgot to mention

Post by Bernard » Mon Nov 13, 2006 5:39 pm

"austria" and "australia" are the two entries in the combo box menu.

tm1274
Posts: 11
Joined: Sun Nov 12, 2006 8:20 pm

Post by tm1274 » Mon Nov 13, 2006 5:41 pm

Thank you very much for the reply, I will try your solution now. I am new to Revolution and have to say I really like the software and it's functionality. And with your post, I feel like the forum is probably a good source of info as well.

marielle
Livecode Opensource Backer
Livecode Opensource Backer

Re: Controlling an image based upon combo box selection

Post by marielle » Mon Nov 13, 2006 5:48 pm

(oups, didn't see somebody already posted the solution. I leave it as a slightly different solution is proposed)

Use the front card as the main one. Either on that card or on a second one, import all the images that you will need to display with the combobox manipulation.

On the main card, create a transparent button and a combobox or pull down menu. Make the transparent button big enough to hold the biggest of the pictures you have to show. Name that button "displayImage"

set the script of the combobox to something of this kind.

Code: Select all

on menupick tPick
  switch tPick
    case "cat"
      set the icon of button "displayImage" to 1010
      break
    case "dog"
      set the icon of button "displayImage" to 1011
      break
    case "lion"
      set the icon of button "displayImage" to 1012
      break
  end switch
end menupick 
Where 1010, 1011, 1012 are the image id of the corresponding images. You can find out what values you should put there by open the custom property palette and click on each image in turn (on the second card) to read their id.

And where "dog", "cat", "lion" are the items that populate the combobox.

Don't hesitate to post another question if you have any problem implementing this solution (I wrote the code on the fly, unchecked, you have to adapt it).


Marielle
Last edited by marielle on Mon Nov 13, 2006 5:52 pm, edited 3 times in total.

tm1274
Posts: 11
Joined: Sun Nov 12, 2006 8:20 pm

Post by tm1274 » Mon Nov 13, 2006 5:49 pm

Bernard's solution worked perfectly. Other than I need to figure out how to use a blank image or not show any image if a selection has not been made. Also are the images used added within the standalone version of the file or do I have to put those in a seperate file?

marielle
Livecode Opensource Backer
Livecode Opensource Backer

Post by marielle » Mon Nov 13, 2006 9:24 pm

tm1274 wrote:Bernard's solution worked perfectly. Other than I need to figure out how to use a blank image or not show any image if a selection has not been made.
Wouldn't a white rectangle do? You can then use set visible of graphic "blancRectangle" to true or false, according to your needs. Alternatively, create a blank image with a graphic program and link to it like you would for any other image.
tm1274 wrote:Also are the images used added within the standalone version of the file or do I have to put those in a seperate file?
With Bernard's solution, you need to provide the files along with the stacks. The problem then is that you need to define the paths to the files as relative to the stack and keep the images in the same directory as the one of the stack to be sure that the images get loaded correctly.

With the other solution, all images will be stored within your stack and no extra manipulation is required (except making sure that you never used cut and paste on the images after importing the images).

Whenever you do anything with images, it is excellent practices to send the stack to a friend to make sure everything works as expected (if you provide a link to the file that is like "c:/xxx/xxx/xxx", then this link will work on your computer, but not on another person's computer) .

Marielle

tm1274
Posts: 11
Joined: Sun Nov 12, 2006 8:20 pm

Post by tm1274 » Wed Nov 15, 2006 3:00 pm

Update on my progress as a newbie:
Using the second card with the images there and a transparent image worked best for my application. I used an image that marched the background color as a place holder so everything is working perfectly so far.

marielle
Livecode Opensource Backer
Livecode Opensource Backer

Post by marielle » Wed Nov 15, 2006 4:36 pm

Thanks for this update!

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”