// Frame Events Example // Adapted from an example in "Learning ActionScript 3.0" by Rich Schupe with Zevan Rosser package { import flash.display.*; import flash.events.*; public class Wk4FrameLoop extends MovieClip { function Wk4FrameLoop( ) { stage.addEventListener(Event.ENTER_FRAME,onFrameLoop); stage.addEventListener(MouseEvent.CLICK, removeFrameLoop); } // Each time frame 1 plays (the only frame), check the position of the mouse // and move the cycles to that position // cycle1 follows the x position of the mouse, so moves left and right // cycle2 follows the y position of the mouse, so moves up and down function onFrameLoop(evt:Event) { cycle1.x = mouseX; cycle1.wheel.rotation = mouseX; cycle2.y = mouseY; cycle2.wheel.rotation = mouseY; } // Once the user clicks the mouse anywhere on the stage, remove the frame listener, // so the cycles will no longer move with the mouse. // Also, remove the mouse click listener function removeFrameLoop(evt:MouseEvent) { stage.removeEventListener(Event.ENTER_FRAME, onFrameLoop); stage.removeEventListener(MouseEvent.CLICK, removeFrameLoop); } } }