点击后重新启动闪存

发布于 2024-12-26 03:06:56 字数 225 浏览 2 评论 0原文

我正在尝试使用重新启动按钮重新启动我的闪存。我使用 gotoAndPlay(0),但没有任何反应。我确定正在调用单击事件处理程序,因为我使用了跟踪语句来验证。

rs.addEventListener(MouseEvent.CLICK, restart);

function restart(event:MouseEvent):void {
    gotoAndPlay(0);
}

I'm trying to restart my flash piece with a restart button. I use gotoAndPlay(0), but nothing happens. I'm sure the click event handler is being called because I used a trace statement to verify.

rs.addEventListener(MouseEvent.CLICK, restart);

function restart(event:MouseEvent):void {
    gotoAndPlay(0);
}

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

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

发布评论

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

评论(2

千里故人稀 2025-01-02 03:06:56

第一帧是帧 1,而不是 0。

不知道为什么 adobe 决定不使帧从零开始,但他们确实这样做了:/

The first frame is frame 1, not 0.

Not sure why adobe decided against making frames zero-based, but they did :/

像你 2025-01-02 03:06:56

如果您已向舞台添加了对象(例如按钮或图形),但从未实际使用过舞台的时间轴,则舞台将启动并停留在第一帧。所以“gotoAndPlay”在这种情况下不起作用。无论如何,只有重新启动动画才有用,因为它不会自行重置任何代码。

您需要决定您实际想要重置哪些部分以及可以保留哪些部分。您可能不想为了再次下载而从开始时加载的内存中删除资源。有些物品可以保留,其他物品则应该移走。

据我所知,除了重新加载整个页面之外,没有简单的方法可以重置 Flash 应用程序。以下是手动“重置”应用程序的一些常规步骤:

  1. 为初始化代码创建一个方法:
    对象创建、添加到显示列表、添加事件侦听器。
  2. 单击:从舞台上删除所有对象,删除其所有事件侦听器。
  3. 再次调用初始化方法。

理想情况下,您将 init 方法中的引用设置为新变量,以便旧变量可以被垃圾收集。根据代码结构,您可能必须手动将某些设置为空。确保不再保留对不再需要的对象的任何引用。

If you have added objects to the stage, like buttons or graphics, but never actually used the stage's timeline, the stage will start and stay at the first frame. So 'gotoAndPlay' wont work in this case. It would be only useful to restart an animation anyway, as it won't reset any code on its own.

You need to decide what parts you actually want to reset and what parts you can keep. You probably don't want to remove assets from memory you loaded at the beginning just to download them again. Some objects may be kept, others should be removed.

As far as I know there is no easy way to reset a flash application, other than maybe reloading the whole page. Here are some general steps to 'reset' an application by hand:

  1. Create a method for your initialization code:
    object creation, adding to the display list, adding event listeners.
  2. On a click: remove all objects from the stage, remove all their event listeners.
  3. Call the initialization method again.

Ideally you set the references in your init method to a new variable so the old ones can be garbage collected. Depending on the code structure you may have to manually set some to null. Make sure you don't keep any references to objects you don't need any more.

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