App INV 2 - How to change images by tapping

2,222 views
Skip to first unread message

mye...@neo.rr.com

unread,
Apr 5, 2014, 2:58:52 PM4/5/14
to mitappinv...@googlegroups.com
Using App Inventor 2 ... How does one change from image to image (back and forth) ? With buttons A  B  C ... Press button A change to C ... then if you press C ... it changes to B ...press B it changes back to C ...and so forth.

SteveJG

unread,
Apr 5, 2014, 3:16:50 PM4/5/14
to mitappinv...@googlegroups.com
I don't know.  It could depend on where the images are stored, where they are placed etc.


I suspect, but do not know, you might want to have Button1 with the text A?  Button2 with the text B? ... and a separate image displayed.  A single image.    or do you have images in the buttons?   Do the buttons have to be labeled?

Have you tried anything?   Have you done the simple tutorials here:   http://appinventor.mit.edu/explore/ai2/tutorials.html   ?

You will need several Button objects, one or more image objects,   knowledge of the set image.picture to block etc.   Do you know where to find these components?

Regards,
Steve

Scott Ferguson

unread,
Apr 5, 2014, 4:37:19 PM4/5/14
to mitappinv...@googlegroups.com, mye...@neo.rr.com
If you are asking about switching between three images on one button then this would be one way:

when Button1.Click do
  if get Button1.Image   = "A.png"
  then set Button1.Image to "C.png"
  else if Button1.Image = "C.png"
  then set Button1.Image to "B.png"
  else if Button1.Image = "B.png"
  then set Button1.Image to "A.png"

---
Scott

mye...@neo.rr.com

unread,
Apr 5, 2014, 9:07:27 PM4/5/14
to mitappinv...@googlegroups.com, mye...@neo.rr.com
@ Steve: A/B/C are all "images".png and uploaded successfully to designer/Media

Button A is the only button that has a label "X" on it The other buttons were made into images/pictures - I am trying to make A an action button so that after you tap A ... you can then tap any of the other images and then make them toggle back and forth between B and C ...Eventually I would like to have a "RESET/WIPE" button where it all goes back to the opening look.

I have tried several of those tutorials and was successful (purrKitty/paintpot etc.) I have also added images and sound when a button is clicked. I just can't seem to be able to link the B/C together so they toggle back and forth ...I could eliminate "A" all together if I could make B/C toggle back and forth upon click.

I can: when A .click - do - set A image - to - "B.png"   ... and it does change to that B image     I can't locate the correct handler to be able to make image B switch to image C and then back again etc.

@ Scott    -   A pic of the color coded "puzzle pieces" events would be perfect b/c I 
Is there a way you can color code these items? I am trying to follow them but they still fail to work properly

THX so much

SteveJG

unread,
Apr 5, 2014, 9:52:30 PM4/5/14
to

Try this.   I did not have images on the buttons, so just used letters.   Is this what you are trying to do with images?  Toggle between them?

Button 1 is B, Button 2 is C.     Press button 1 and it becomes C and button2 becomes B.

Button3 is a reset button...both buttons revert to their original captions ... or in your case you will be substituting   set image1.Picture to     xxxx.png    set image2.Picture to  yyyy.png

Regards,
Steve

mye...@neo.rr.com

unread,
Apr 5, 2014, 11:11:32 PM4/5/14
to mitappinv...@googlegroups.com
I just wanted to thank you for your help. The RESET Button worked perfectly. 
I then changed all of the "text" boxes to "image" to account for the .png image.

The pic I attached looks slightly different then the one you posted, I removed several items b/c when ever I was clicking on Button 1 ... it was causing Button 2 to appear and never move again until reset. The pic also has some of the changes that were made to get the images do what they were supposed to do.

Is there anywhere I can put your gold star for helping me with this issue?
THX again,
Kryptanite


On Saturday, April 5, 2014 9:49:53 PM UTC-4, SteveJG wrote:

Try this.   I did not have images on the buttons, so just used letters.   Is this what you are trying to do with images?  Toggle between them?

Button 1 is B, Button 2 is C.     Press button 1 and it becomes C and button2 becomes B.

Button3 is a reset button...both buttons revert to their original captions ... or in your case you will be substituting   set image1.Picture to     xxxx.png    set image2.Picture to  yyyy.png

Regards,
Steve





On Sunday, April 6, 2014 1:07:27 AM UTC, mye...@neo.rr.com wrote:
Button Toggle.png

Enis

unread,
Apr 5, 2014, 11:32:44 PM4/5/14
to
Steve deserves many, many gold stars!  I'm sure he'll see this tomorrow and smile!  Your message is enough, but Steve, consider yourself "starred!"

And thanks for coming back and letting us know you're again on the right track!

So glad you got it working...



On Saturday, April 5, 2014 11:11:32 PM UTC-4, mye...@neo.rr.com wrote:
I just wanted to thank you for your help. The RESET Button worked perfectly. 

SteveJG

unread,
Apr 6, 2014, 8:55:33 AM4/6/14
to mitappinv...@googlegroups.com
I was glad to help Kryptanite. I amhappy that the solution worked.   They do not give us stars, points, special favors, or money.  We are all volunteers .. I gladly accept the stars.
Good luck with your App.

Regards,
Steve
Reply all
Reply to author
Forward
0 new messages