Flash dispatches Events
for most of its objects. One of the most basic event is ENTER_FRAME
, which is dispatched (at the framerate of the SWF) on every display list object.
import flash.display.Sprite;
import flash.events.Event;
var s:Sprite = new Sprite();
s.addEventListener(Event.ENTER_FRAME, onEnterFrame);
function onEnterFrame(e:Event)
{
trace("I am called on every frame !");
}
This function will be called asynchronously on every frame. This means the function that you assign as the onEnterFrame
event handler is processed before any other ActionScript code that is attached to the affected frames.