For users who prefer to learn Flash visually we have a range of Adobe Flash CS3 video tutorials, this method of training greatly enhances learning and allows beginners to master even the most complex aspects of Adobe Flash with ease.
View the Flash CS3 Tutorial Videos .
Interactivity with Flash – Event Handling
The code used in this Flash Tutorial is mainly ActionScript 2.0 with notes for using ActionScript 3.0
This tutorial comprises an introduction to interactivity in Flash, including the underlying principle of Event Handling.
Please note that Event Handling changed significantly between ActionScript 2.0 and 3.0.
myclip_mc.onPress = function() { trace(“press”); };
This code instructs the movie to listen for the mouse press event on the movie clip symbol, and, when a mouse press is detected, to execute the code within the brackets. This statement is assigning a function to the movie clip onPress event, meaning that Flash Player should carry out the function whenever the event fires.
If you’re using ActionScript 3.0, your code will be slightly different:
myclip_mc.addEventListener(“onPress”, clipPressed);
function clipPressed() { trace(“press”); };
This code has the same effect as the code above. It tells the movie to listen for the onPress event on myclip_mc and then execute the code within the clipPressed function specified.
Test your movie (CTRL + Enter or Control > Test Movie); click on the shape, you should see “press” written to the output panel:
There are many events that ActionScript can listen for. For example, to detect the mouse cursor rolling over your movie clip, change onPress (or onRelease) to onRollOver. Test your movie, then roll the mouse on and off the shape; the event should fire each time the cursor moves onto the shape. Try changing onRollOver to onRollOut and test again. This time the event fires when the cursor moves off the shape.
Experiment with the different events to familiarise yourself with them; you can also use button symbols, which have a degree of interactivity built-in, meaning that you may need to write less (if any) ActionScript code yourself.
Tagged: ActionScript 3, Flash CS3, Flash Event Handling, Tutorials
