ActionScript has long since relied on the enterFrame (onEnterFrame) event for time-based actions, especially animation and actions relating to frame playback. In comparison, Director’s Lingo language has, not only an enterFrame event, but two other frame events, prepareFrame and exitFrame. Though ActionScript 3 has not aquired prepareFrame or exitFrame, it has gained a new frame event, render, or Event.RENDER (flash.events.Event.RENDER).
The render event in AS3 is a frame event that occurs after enterFrame (flash.events.Event.ENTER_FRAME) allowing one more chance to do what you need to do before the screen updates its display.
Unlike enterFrame, however, the render event will not be called unless the display object using it is attached to a stage (or in any display list attached to the stage). Also, render is not automatically called every frame, even if attached to the stage. In order for render to be called for the current frame, you must make a call to stage.invalidate() (flash.display.Stage.invalidate());
about invalidate :
Calling the invalidate() method signals Flash Player to alert display objects on the next opportunity it has to render the display list (for example, when the playhead advances to a new frame). After you call the invalidate() method, when the display list is next rendered, Flash Player sends a render event to each display object that has registered to listen for the render event. You must call the invalidate() method each time you want Flash Player to send render events.
Example :
stage.addChild(sprite);
sprite.addEventListener(Event.ENTER_FRAME, enterFrame);
sprite.addEventListener(Event.RENDER, render);
stage.addEventListener(MouseEvent.CLICK, click);
function enterFrame(event:Event):void {
trace(“enter frame”);
}
function render(event:Event):void {
trace(“render”);
}
function click(event:MouseEvent):void {
trace(“click”);
stage.invalidate();
}
Output Result :
enter frame
enter frame
enter frame
click
enter frame
render
enter frame
enter frame
enter frame
enter frame
…
You might also like
| Events and Event Types in AS3 Event objects used with EventDispatcher in ActionScript 3 are a little less generic than those used with ActionScript... | EventDispatcher in AS3 ActionScript 3 uses the EventDispatcher (flash.events.EventDispatcher) class for all event handling. This class... | TextField in AS3 1. Create a - Flash File(ActionScript 3.0) 2. Now go to your Actions tab, you can do this by pressing F9, or... | FullScreen in AS3 Notes: This tutorial covers HTML changes as well. Flash requires an HTML to be in opened in your browser and load... |







