Stop all players / Make all images invisible / If the screen is touched do ???

735 views
Skip to first unread message

Slider

unread,
Feb 9, 2018, 5:18:27 AM2/9/18
to MIT App Inventor Forum
Hello!
First of all: I didnt find any answer to my questions so Im posting here for the first time :) And please excuse my english skills, I havent been good at learning languages :x

What do I want to program?
The app has only a single screen with some buttons. If a button is pressed a sound  should start and an image should be displayed. If the screen is touched, any sound should stop and any image should disappear, so the next button can be pressed.

What I have:
buttons, invisible images and players

The code is:

when "button".click do
call "sound1".start
set "image1".visible to true

would that work?

What I need is:
when screen is touched do
end all players
set all images visible to false


Greetings
Slider



TimAI2

unread,
Feb 9, 2018, 6:14:04 AM2/9/18
to MIT App Inventor Forum
Easiest way is to do the following:

Add a canvas and an imagesprite inside the canvas - these could be not visible...

On button "PLAY" load image you want to imagesprite, set canvas and imagesprite to visible and fill parent, play the sound, set all other components invisible

You then need blocks for the canvas touched (or imagesprite touched) event to unhide the other components and stop the player 

You may find it easier to put all your buttons inside an arrangement, then all you need to do is change the visibility of the arrangement.

Slider

unread,
Feb 10, 2018, 2:33:08 PM2/10/18
to MIT App Inventor Forum
Hi!
Thanks so far!

Is there any way to make all player stop with just one block?

Greetings

Slider

unread,
Feb 11, 2018, 7:43:36 AM2/11/18
to MIT App Inventor Forum
Another question: is it possible to set all canvas visible to false?

TimAI2

unread,
Feb 11, 2018, 9:03:06 AM2/11/18
to MIT App Inventor Forum
For both of the above:

Use lists and the any component blocks to do this




If you haven't done it already....


Slider

unread,
Feb 11, 2018, 3:47:28 PM2/11/18
to MIT App Inventor Forum
Seems like I didnt read enough :x

I will try that tomorrow, thanks!

Slider

unread,
Feb 12, 2018, 7:49:39 AM2/12/18
to MIT App Inventor Forum
Hi!
I did that and tested it as .apk, but that app crashes soon. Any idea why? Did I upload too much stuff? Here is my app

Thanks!

TimAI2

unread,
Feb 12, 2018, 11:18:55 AM2/12/18
to mitappinv...@googlegroups.com
I am guessing it it crashing because of the screen switching you have in place, in that screens are probably not closing properly
Have a look at the links below to understand how to switch screens. i also attach an aia of a screen switching example.

In terms of your app:
  • Consider not using different screens, just visible/hidden arrangements
  • You could use buttons instead of canvases for your images, or image components then use Juan Antonio's image extension to make them clickable
  • You could have just one set of buttons that you load for each set of names, tunes and images instead of having one for each, using the lists you already have
  • You need to put the "Hide and Stop" procedure into each of the button/image blocks
  • You can combine the player stop and image hide into one if/else in your button blocks, you do not need two if statements
  • Nice stag :) Nice tunes :)


Use different screens wisely

If you decided to use different screens, then you should switch them correctly, else you will run out of memory after a while...      
The recommended method of switching screens in App Inventor
(Thanks Taifun)
multiscreen.aia
Reply all
Reply to author
Forward
0 new messages