Thursday, April 8, 2010


  • Description:

Event handler; invoked continually at the frame rate of the movie. The actions associated with the enterFrame clip event are processed before any frame actions that are attached to the affected frames.

You must define a function that executes when the event is invoked.This Event Handler Function is called at the start of each frame of display, whether the associated object is playing or not. However, if the sprite is removed, then the onEnterFrame actions are no longer processed. The Actions associated with the Event are processed before any Frame Action events for the object.

If "includingFirstFrame" is specified, then the actions will be processed on all frames of display starting from and including the very first frame that the object is placed. If "excludingFirstFrame" is specified, then it will not run for the first time until the frame AFTER the object is placed. Compare this with the onLoad Event Handler Function, which will run ONLY for the first frame of display.

The default if you specify neither option is "excludingFirstFrame" (this is the same behaviour as Flash uses for its enterFrame clip event).

This Event Handler is an ideal place to install collision detection routines for games, etc.

  • Syntax:

onEnterFrame = function() {}

  • Example of onEnterFrame:

1) The following example defines a function for the onEnterFrame event handler that sends a trace() action to the Output panel:

mc.onEnterFrame = function () {

2) The following example defines a function for the onEnterFrame event handler that increase the size of a variable "i" by one and display it to a dynamic text "digit".

var i:Number = 0;
this.onEnterFrame = function() {
    i = i+1;
    digit.text = i;

  • onEnterFrame vrs setInterval:

onEnterFrame's time intervals are equal to the frame rate set in the document properties. If you want to run some code at different intervals of time, onEnterFrame won't be able to do the job. This is where setInterval is used. setInterval works like onEnterFrame except the time intervals are independent of the document's set frame rate. The timer measures the intervals in milliseconds, so you can run a function many times faster or slower that the document's frame rate.

No comments:

Post a Comment