Events in ActionScript3

One interesting event we can listen for is the EnterFrame event. This event occurs every time we enter a frame. If your movie has a speed of 24 frames per second the EnterFrame event occurs 24 times per second even if there is only one frame. This event is good for animation because it doesn't require anything from the user.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. Name the layer star and create a new layer for the actionscript.
  5. Write the code as shown below:
function frames(e:Event): void { 

We have told Flash to execute a function called frames every time the ENTER_FRAME event occurs. The code in the function gives a new value to star.rotation that is one more than its current value.

This says that the function frame receives an argument named e that is type Event.
The colon followed by the word void means that the function does not return anything.
The body of the function, the lines of code that are executed, are enclosed between { and }

Experiment: Modify the code to subtract 1 instead of adding 1. Change the 1 to a 3 or 5.

Debugging: If you star does not spin, but rather looks like it is in orbit, the registration point is not in the center. You can move the registration point by double clicking on the star and moving the drawing so that the + is in the middle. If it still doesn't work, open the finished movie and check carefully to find what you did wrong.

NEXT: A Moving Ball, The trace() command