为什么没有调度 Event.RENDER?
我创建了一个类,它必须注册到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须调用
stage.invalidate()
方法来调度Event.RENDER
事件。根据 AS3 参考,Event.RENDER
在屏幕渲染之前调度,为所有侦听对象提供更新的机会。仅当某些内容更改了静态形状的参数时,我才使用Event.RENDER
重新绘制静态形状。它比重新绘制每一帧要快。You must call the
stage.invalidate()
method to dispatch theEvent.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 usedEvent.RENDER
to redraw static shapes only when something has changed their parameters. It's faster than redrawing every frame.