Watching:

Working with events


show more Working with events provides you with in-depth training on Web. Taught by Todd Perkins as part of the Flash CS3 Professional Beyond the Basics show less
please wait ...

Working with events

Now we'll talk about events and event handlers. Events are things that happen. One example of an event is a mouse click. Another example is when a file finishes downloading or when a song finishes playing. So those are some examples of events and again they're just things that happen. An event handler is a function that responds to the event. For example when a person clicks on a button something happens, the button navigates to a certain frame. Event handler is what controls that functionality, or what block of code runs when a certain event happens.

So let's take a look at writing an event handler function. If you're following along the file I'm working in is called 03_Events.fla in the Chapter 02 folder in the Exercise Files folder. Select the first keyframe of the Actions layer and open the Actions panel using the keyboard shortcut Option+F9 on the Mac or F9 on the PC. In the Actions panel, define a function. Let's say this function is running when a person's mouse clicks a certain button. So I'm going to call this buttonClicked with capital C. That's the name of the function.

It's going to received a value. I'm going to give the name of the value of event. When an event handler function runs, it receives information about the event that happened. So we need to create a parameter to accept that event. And I'm calling the parameter event here. I'm going to type a colon to declare the data type of the event, and because the event happens with the mouse, it's classified under the data type MouseEvent And again it has a capital M. So MouseEvent, capital E. The returned data type for event handlers is almost always void.

And other than that an event handler looks pretty much just like a function. And there's a look in creating a function that reacts to an event. Now let's make this function do something very simple. So I'll type Trace. Remember a trace statement makes something appear in the output window. And then parentheses after trace, I'm going to type in a value in quotes. The value is going to be "button clicked". So whenever this event handler function runs, the message "button clicked" will appear in the Output window. Now, in order for this function to run we need to connect it to some sort of object and we'll talk about that in the next movie.

Working with events
Video duration: 2m 11s 5h 21m Intermediate

Viewers:

Working with events provides you with in-depth training on Web. Taught by Todd Perkins as part of the Flash CS3 Professional Beyond the Basics

Subject:
Web
Software:
Flash Professional
Author:
please wait ...