Chapter 6. ADDING INTERACTIVITY WITH ACTIONSCRIPT

Handling user input is what makes an application tick. Dealing with mouse clicks, dragging, typing on the keyboard, and such is where the fun is. Otherwise, you wouldn’t have an application; you’d have just an animation or a static image, and that’s, well, comparatively boring.

However, understanding what someone using your application does and responding to that action takes some planning and work. You have to account for every interaction that you think is important. Basically, you’re thinking about what a user might want to do and preparing for that. Of course, this can be a challenge, but it can be really rewarding as well.

Understanding Events

A Flex application responds to user input by something called an event. An event is something that happened, either by user interaction, or by other things happening such as a photo appearing or data returning from a server. (Getting data from a server is covered briefly in Chapter 10.) When a user clicks a button, for instance, an event occurs. (The event for clicking something is called—you guessed it—click.) And when a button is created, an event also occurs. (This event is called creationComplete.) When the event happens, you say the event fired or was dispatched. To respond to such an event, you set up something called an event handler or listener.

Handling Events Inline

MXML makes listening for events very simple. All you have to do is add the proper event attribute to a tag and tell ...

Get Learning Flex 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.