Events

AppInventor programs use event handler blocks to specify how the program should respond to certain events. After, before, or when the event happens can all call different event handlers. There are two types of events: user-initiated and automatic.

  • Clicking a button, touching or dragging the screen, and tilting the phone are user-initiated events.
  • Sprites colliding with each other or with canvas edges are automatic events.
  • Another type of automatic event is a timer event. Clock components and sprite components have a TimerInterval property. Every time the interval is up, or the timer "ticks", a timer event is triggered for that object.
  • Another type of user-initiated event is a sensor event . OrientationSensor, Accelerometer, and LocationSensor all have events that get called when the user moves the phone in a certain way or to a certain place.
  • Most event handlers are green in color and are stored at the top part of each drawer. Here are some examples of event handlers.

    Make sure you know the difference between events and procedures. Button1.Click is an event. Sound1.Play is a procedure.
    For some more practice using event handlers for gaming, use the Tilt-A-Color tutorial found below.
    Ad-App-tation: Tilt-A-Color
    
    Make the background canvas change color based on orientation sensor reading with the TiltAColor app.

    << Return to the main page for Lesson 2.1 to check out additional game design resources.