This tutorial will teach you how to create simple event mechanism.
First, create MovieClip ball, place instance on Stage and name that instance mc_ball. Then, enter next code in first and only frame on main Timeline and test your movie.
Function doIt() is activated when some event happens. In this case, when ball x coordinate is smaller than 25. Function doIt() places ball on right side of Stage. Point is that doIt() executes only once but it is placed on onEnterFrame for instance. In this way you can create very complex movements and reactions.
For example, you can write event2, …, event3, etc and every event reacts on different occasion. Also, you can use different actions and function when event1 AND event2 are true, but something else when only event1 has values true. You can also put within onEnterFrame function for root, doIt() function inside for or while loop for multiple executions. Simple code, but useful.