为什么没有调度 Event.RENDER?

发布于 2024-08-02 05:39:06 字数 768 浏览 3 评论 0原文

我创建了一个类,它必须注册到 Event.RENDER 事件,以便它知道舞台何时被渲染。我的代码的简化版本如下所示:

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!");
        }
   }
}

正在调度 Event.ADDED_TO_STAGE 事件。但是,Event.RENDER 事件则不然。知道我在这里可能做错了什么吗?父级将此对象作为子级添加到舞台中,因此这不会是问题。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

魂ガ小子 2024-08-09 05:39:06

您必须调用 stage.invalidate() 方法来调度 Event.RENDER 事件。根据 AS3 参考Event.RENDER 在屏幕渲染之前调度,为所有侦听对象提供更新的机会。仅当某些内容更改了静态形状的参数时,我才使用 Event.RENDER 重新绘制静态形状。它比重新绘制每一帧要快。

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 used Event.RENDER to redraw static shapes only when something has changed their parameters. It's faster than redrawing every frame.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文