Page 1 of 1

Controlling an image based upon combo box selection

Posted: Mon Nov 13, 2006 5:23 pm
by tm1274
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

Posted: Mon Nov 13, 2006 5:38 pm
by Bernard
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).

forgot to mention

Posted: Mon Nov 13, 2006 5:39 pm
by Bernard
"austria" and "australia" are the two entries in the combo box menu.

Posted: Mon Nov 13, 2006 5:41 pm
by tm1274
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.

Re: Controlling an image based upon combo box selection

Posted: Mon Nov 13, 2006 5:48 pm
by marielle
(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

Posted: Mon Nov 13, 2006 5:49 pm
by tm1274
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?

Posted: Mon Nov 13, 2006 9:24 pm
by marielle
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

Posted: Wed Nov 15, 2006 3:00 pm
by tm1274
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.

Posted: Wed Nov 15, 2006 4:36 pm
by marielle
Thanks for this update!