第三次播放帧时出错

发布于 2024-11-18 08:11:14 字数 1314 浏览 7 评论 0原文

我有一个 Flash 文件,其中第一帧包含两个按钮,其中一个将用户带到第二帧,另一个将用户带到第三帧。在每个框架中,可以通过 SimpleButtons 操作各种文本字段和变量。第 2 帧和第 3 帧都有“后退”按钮,可以将它们带回到第 1 帧。

目前,当用户第二次导航回第 1 帧(从而第三次播放)时,我的第二个按钮似乎不再存在,我收到一个错误。第 1 帧上的两个按钮都是通过 Flash IDE 放置的。为什么我的按钮在前两次都运行良好的情况下突然消失了?下面是我的第 1 帧代码。“后退”按钮简单地删除事件侦听器,然后调用 gotoAndStop(1)

var inited:Boolean;
var cache:SharedObject;
var libsans:Font = new libsansreg();

this.addEventListener(Event.ENTER_FRAME, frameEnter);
stats.addEventListener(MouseEvent.CLICK, statsclicked);
modules.addEventListener(MouseEvent.CLICK, modsclicked);

function initcache():void
{
    this.cache = SharedObject.getLocal("RPG_Shooter")
}

function frameEnter(e:Event):void
{
    if (!inited)
    {
        inited = true
        initcache()
        this.gotoAndStop(1)
    }
}

function statsclicked(e:MouseEvent):void
{
    this.removeEventListener(Event.ENTER_FRAME, frameEnter)
    stats.removeEventListener(MouseEvent.CLICK, statsclicked)
    modules.removeEventListener(MouseEvent.CLICK, modsclicked)
    this.gotoAndStop(2)
}

function modsclicked(e:MouseEvent):void
{
    this.removeEventListener(Event.ENTER_FRAME, frameEnter)
    stats.removeEventListener(MouseEvent.CLICK, statsclicked)
    modules.removeEventListener(MouseEvent.CLICK, modsclicked)
    this.gotoAndStop(3)
}

I have a flash file where the first frame contains two buttons, one of which takes the user to the second frame, and the other takes them to the third frame. At each of those frames, various text fields and variables can be manipulated via SimpleButtons. Both Frame 2 and Frame 3 have "back" buttons to take them back to Frame 1.

Currently when the user navigates back to Frame 1 for the second time (thus playing it for a third time), my second button appears to no longer exist, and I receive an error. Both buttons on Frame 1 were placed via the Flash IDE. Why is my button popping out of existence, when it did perfectly fine the previous two times? Below is my code for Frame 1. The "back" buttons simple remove event listeners and then call gotoAndStop(1)

var inited:Boolean;
var cache:SharedObject;
var libsans:Font = new libsansreg();

this.addEventListener(Event.ENTER_FRAME, frameEnter);
stats.addEventListener(MouseEvent.CLICK, statsclicked);
modules.addEventListener(MouseEvent.CLICK, modsclicked);

function initcache():void
{
    this.cache = SharedObject.getLocal("RPG_Shooter")
}

function frameEnter(e:Event):void
{
    if (!inited)
    {
        inited = true
        initcache()
        this.gotoAndStop(1)
    }
}

function statsclicked(e:MouseEvent):void
{
    this.removeEventListener(Event.ENTER_FRAME, frameEnter)
    stats.removeEventListener(MouseEvent.CLICK, statsclicked)
    modules.removeEventListener(MouseEvent.CLICK, modsclicked)
    this.gotoAndStop(2)
}

function modsclicked(e:MouseEvent):void
{
    this.removeEventListener(Event.ENTER_FRAME, frameEnter)
    stats.removeEventListener(MouseEvent.CLICK, statsclicked)
    modules.removeEventListener(MouseEvent.CLICK, modsclicked)
    this.gotoAndStop(3)
}

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

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

发布评论

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

评论(1

美羊羊 2024-11-25 08:11:14

我实际上曾经遇到过类似的问题。它与垃圾收集有关,垃圾收集本来就不是 Flash 中最好的,但 IDE 的编译器设置使其变得更加疯狂。您可以尝试一些可能会有所帮助的技巧。

  • 确保在离开框架之前删除所有侦听器。
  • 转到“空白”框架(仍然具有背景和样式,但没有可交互组件的东西),即使是 5/1000 秒 在第一帧
  • 上将变量名称设置为“null”(因此,如果您的组件在第 3 帧被命名为“foo”,在第 1 帧上放置 foo = null),
  • 在第 1 帧上放置 var foo:MovieClip。对您可能使用的所有已命名的 MovieClip 重复上述操作领先于 时间。

I actually had similar problem at one point. It has to do with garbage collection which is not the best in Flash to begin with, but the IDE's compiler settings make it so much more insane. There are a couple of tricks you can try which might help.

  • Make sure you remove all listeners before leaving the frame.
  • Go to a "blank" frame (something which still has a background and styling, but no interact-able components) for even a 5/1000 of a second
  • Set the variable names to "null" on frame one (so if your component on frame 3 is named "foo" put foo = null on frame one)
  • put var foo:MovieClip on frame 1. repeat for all MovieClips which you might be using that are named ahead of time.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文