// Frame Events Example with two frame loops controlling two // MovieClips, cycle1 and cycle2, on two different frames. // // On frame 1, a frame loop repeatedly goes to frame 1 and stops, // so that only frame 1 will play repeatedly and move cycle1 // On frame 2, a frame loop repeatedly goes to frame 2 and stops, // so that ony frame 2 will play repeatedly and move cycle2 // A button controls when the action moves from the first frame // to the second frame. Before moving to the second frame, the // button handler removes the frame 1 ENTER_FRAME listener. // After moving to the second frame, it adds the frame 2 // ENTER_FRAME listener. package { import flash.display.*; import flash.events.*; public class Wk4ButtonFrameLoop extends MovieClip { function Wk4ButtonFrameLoop( ) { nextBtn.addEventListener(MouseEvent.CLICK, gotoNextPage ); stage.addEventListener(Event.ENTER_FRAME,page1FrameLoop); } // When nextBtn is clicked, go to 2nd frame function gotoNextPage( evt: MouseEvent ) { stage.removeEventListener(Event.ENTER_FRAME,page1FrameLoop); gotoAndStop( 2 ); stage.addEventListener(Event.ENTER_FRAME, page2FrameLoop); } // Each time frame 1 plays, check the position of the mouse // and move the cycles to that position. Then play frame 1 again. // cycle1 follows the x position of the mouse, so moves left and right function page1FrameLoop(evt:Event) { cycle1.x = mouseX; cycle1.wheel.rotation = mouseX; gotoAndStop( 1 ); } // Each time frame 2 plays, check the position of the mouse // and move the cycles to that position. Then play frame 2 again. // cycle2 follows the y position of the mouse, so moves up and down function page2FrameLoop(evt:Event) { cycle2.y = mouseY; cycle2.wheel.rotation = mouseY; gotoAndStop( 2 ); } } }