Controlling an image based upon combo box selection
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Controlling an image based upon combo box selection
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?
simple example
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).
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).
forgot to mention
"austria" and "australia" are the two entries in the combo box menu.
-
- Livecode Opensource Backer
Re: Controlling an image based upon combo box selection
(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.
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
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
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.
-
- Livecode Opensource Backer
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: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.
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.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 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