循环设置点击按钮事件

问题描述 投票:0回答:1

在我的应用程序中,我创建了一个单击图像的函数:

to myfunc ( button )
  do ...

有多个按钮具有相同的操作:

when image1.Touched
  x  y
do call myfunc
          button( image1 )

when image2.Touched
  x  y
do call myfunc
          button( image2 )

when image3.Touched
  x  y
do call myfunc
          button( image3 )
... 

我可以在循环内为它们设置点击事件吗?

app-inventor
1个回答
0
投票

您可以在每个按钮单击事件中调用相同的过程,并将按钮 id 作为输入参数传递

when button1.Click do 
  call myProcedure "1"...

when button2.Click do 
  call myProcedure "2"...

when button3.Click do 
  call myProcedure "3"...

when button4.Click do 
  call myProcedure "4"...

然后在 for Each 循环中,您可以执行类似的操作(假设有 4 个按钮)并将当前数字传递给过程

for each number from 1 to 4 do
  call procedure "number"

学习 App Inventor 的一个非常好的方法是阅读 AI2 免费在线电子书中的免费 Inventor 手册 http://www.appinventor.org/book2 ...链接位于网页底部。这本书“教”用户如何使用 AI2 块进行编程。 这里有一个免费的编程课程http://www.appinventor.org/content/CourseInABox/Intro,书中项目的 aia 文件位于:http://www.appinventor.org/bookFiles
这里描述了如何使用 App Inventor 做很多基本的事情:http://www.appinventor.org/content/howDoYou/eventHandling .

还可以阅读教程 http://appinventor.mit.edu/explore/ai2/tutorials.html 学习 App Inventor 的基础知识,然后尝试一些东西并遵循 前 5 个提示:如何学习 App Inventor

© www.soinside.com 2019 - 2024. All rights reserved.