开发者

stage Event.ENTER_FRAME vs. CREATION_COMPLETE

I've got an AS3 project that I'm building in FlexBuilder.

In my main class's constructor, I've got this:

    stage.addEventListener(Event.ENTER_FRAME, stage_enterFrameHandler);

And then the event handler function:

    private var tempCounter:uint = 0;

    private function stage_enterFrameHandler(event:Event):void
    {
        stage.removeEventListener(Event.ENTER_FRAME, stage_enterFrameHandler);
        tempCounter += 1;
        trace(tempCounter);
    }

When I run in debug mode, tempCounter w开发者_如何学Crites out once, as 1. Why is this? I though the whole point of Event.ENTER_FRAME is that it keeps firing.

The documentation says:

If the playhead is not moving, or if there is only one frame, this event is dispatched continuously in conjunction with the frame rate. This event is dispatched simultaneously to all display objects listening for this event.

So why would I not see that counter incrementing about 30x a second (which is what I have the frame rate set to)?

EDIT NOTE:

OK, well, doh, I've figured it out. It's because I immediately remove the eventlistener. The ENTER_FRAME event does keep firing... The only reason the code is done this way (code I inherited) is, I suppose, that CREATION_COMPLETE isn't available if you aren't using the flex framework.


The answer is simple as soon as enter in your enter frame you are removing the listener so the next time the enter frame event occured there is no one to react to it.

remove the line

stage.removeEventListener(Event.ENTER_FRAME, stage_enterFrameHandler);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜