views:

534

answers:

1

I made a class, which has to register to the Event.RENDER event so that it will know when the stage is being rendered. The simplified version of my code looks like this:

package
{
   import flash.events.Event;
   import flash.display.Sprite;
   public final class Test extends Sprite
   {
        public final function Test()
        {
            addEventListener(Event.ADDED_TO_STAGE,added,false,0,true);
        }

        private final function added(event:Event):void
        {
            trace("added to stage");
            stage.addEventListener(Event.RENDER, renderHandler,false,0,true);
        }

        private final function renderHandler(event:Event):void
        {
            trace("Event.RENDER dispatched!");
        }
   }
}

The Event.ADDED_TO_STAGE event is being dispatched. However, the Event.RENDER event is not. Any idea what I may be doing wrong here? The parent is adding this object as a child to the stage, so that can't be the problem.

+1  A: 

You must call the stage.invalidate() method to dispatch the Event.RENDER event. According to the AS3 reference, Event.RENDER is dispatched just before the screen is rendered, giving all listening objects the chance to update. I've use Event.RENDER to redraw static shapes only when something has changed their parameters. It's faster than redrawing every frame.

Evan Kroske