Code Snippets

Code Snippets are prewritten snippets of code that you can insert into your movie. They always have to be modified, but they are a good way to get started with code. Get Adobe Flash player

  1. Create a new movie and draw a star.
  2. Make the star a movie clip with the registration in the center
    registration in center
  3. Name the instance of the star on the stage star in the properties window.
  4. Click the stage so that nothing is selected.
  5. Open the actions panel (From the menu select Window, Actions or F9.)
  6. Click Code Snippets in the top right corner and double click Enter Frame Event.
    snippets
  7. A new layer called Actions will be inserted and the code shown below will be inserted:
    /* Enter Frame Event
    Executes the function fl_EnterFrameHandler defined below each time the playhead moves into a new frame of the timeline.
    
    Instructions:
    1. Add your custom code on a new line after the line that says "// Start your custom code" below.
       The code will execute when the playhead moves into a new timeline frame.
    */
    
    addEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler);
    
    function fl_EnterFrameHandler(event:Event):void
    {
    	//Start your custom code
    	// This example code displays the words "Entered frame" in the Output panel.
    	trace("Entered frame");
    	// End your custom code
    }
  8. Modify the code as shown bleow:
    addEventListener(Event.ENTER_FRAME, frames);
    
    function frames(e:Event):void
    {
    	star.rotation++;
    }
    Assuming the frame rate (FPS: frames per second) is 24, the enter frame event occurs 24 times per second even if you have just one frame in the movie.

NEXT: Spin with enter frame event