|
ActionScript Reference Movie Clip Control
MovieClip.onEnterFrame()
MovieClip.onEnterFrame()
Entry Owner: Alvin Liuson, Started: November 7, 2003
Description
MovieClip.onEnterFrame is a very powerful function. It allows you to run whatever code you want on every frame of your Flash movie. The function name is a bit deceiving to the newbie Flash developer. The term "frame" in this case refers more to the "frame rate" of the Flash movie, rather than a particular "keyframe" that the function has to "enter."
Basically, this is how it works: if you have a movie that's running at 12 frames per second (FPS), the onEnterFrame function will fire 12 times a second. If the frame rate is 30 FPS, the onEnterFrame will fire 30 times a second (that is, of course, if the CPU is able to keep up). The more you use it, the more you will appreciate its power and flexibility. You can use it to animate objects or act as a pseudo callback function.
One thing to note is that onEnterFrame is a method of the MovieClip object. You can't attach it to a Button or an Object and expect it to work.
Availability:
Flash Player 6, although onClipEvent(enterFrame) is available in Flash Player 5.
Usage
MovieClip.onEnterFrame = function() {
// your statements here
}
Parameters
None.
Returns
Nothing.
Examples:
This example moves movieclip "square" one pixel for each time that the onEnterFrame fires. Place this code in the main timeline in the same keyframe that you create "square":
//"this" refers to _level0, or _root, which is itself a MovieClip
this.onEnterFrame = function () {
square._x +=1;
}
More examples to follow...stay tuned!
|