【问题标题】:Flash CS6 Error #1009 - Button disappearsFlash CS6 错误 #1009 - 按钮消失
【发布时间】:2012-08-05 02:09:18
【问题描述】:

我第一次开始使用 Flash CS6 来尝试为 UDK 制作 Scaleform UI。我正在学习这个简单的教程:http://goo.gl/yedMU。我已经按照信函进行了操作,但似乎无法使其正常工作。我什至在一个新项目中再次尝试过,但最终还是出现了同样的错误。我已经三次检查了每个名称和实例,但它只是拒绝工作。这是文件中两个框架的真正简单代码:

import flash.events.MouseEvent;
import flash.system.fscommand;
import flash.display.MovieClip;

subMenu_btn.addEventListener(MouseEvent.CLICK, subMenu);
exit_btn.addEventListener(MouseEvent.CLICK, exitGame);

var cursor:cursor_mc = new cursor_mc();
addChild(cursor);
     cursor.x = mouseX;
     cursor.y = mouseY;
cursor.startDrag();

stop();

function subMenu(event:MouseEvent):void
{
     gotoAndStop('Sub Menu');
}
function exitGame(event:MouseEvent):void
{
     fscommand('ExitGame');
}

play_btn.addEventListener(MouseEvent.CLICK, playGame);
back_btn.addEventListener(MouseEvent.CLICK, backBtn);

function playGame(event:MouseEvent):void
{
     fscommand('PlayMap');
}
function backBtn(event:MouseEvent):void
{
     gotoAndStop('Main Menu');
}

我使用了调试器,代码中断了

exit_btn.addEventListener(MouseEvent.CLICK, exitGame);

有什么想法吗?整个过程一直有效,直到我使用“返回”按钮返回第一帧,当“退出”按钮消失并且我收到该错误时。但是,“子菜单”按钮仍然存在,并且菜单仍然可以操作。

这是使用调试器的错误:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Menu_fla::MainTimeline/frame1()[Menu_fla.MainTimeline::frame1:6]
at flash.display::MovieClip/gotoAndStop()
at Menu_fla::MainTimeline/backBtn()[Menu_fla.MainTimeline::frame2:10]

【问题讨论】:

  • “主菜单”框架上是否有“exit_btn”?您是在告诉 Flash 监听不存在的内容。右侧有一个侧边栏,里面有和你有同样问题的人,你可能想看看。
  • 我浏览了这些帖子中的每一篇,但没有找到答案。这是项目,您可以看到它:sendspace.com/file/f8y82w
  • 我相信正在发生的事情是,每次您更改帧时,Flash 都会NULLing 出所有的影片剪辑;如果您调试并查看此-> exit_btn(其值为空),您可以看到这一点。我将在答案部分发布我的建议。

标签: actionscript-3 flash flash-cs6


【解决方案1】:

好的,所以我上面的cmets说的可能有误,解决办法是这样的:

对于您的第一帧 AS3:

import flash.events.MouseEvent;
import flash.system.fscommand;
import flash.display.MovieClip;

var cursor:cursor_mc = new cursor_mc();

subMenu_btn.addEventListener(MouseEvent.CLICK, subMenu);
exit_btn.addEventListener(MouseEvent.CLICK, exitGame);

addChild(cursor);
     cursor.x = mouseX;
     cursor.y = mouseY;
cursor.startDrag();
Mouse.hide();

stop();

function subMenu(event:MouseEvent):void
{
    subMenu_btn.removeEventListener(MouseEvent.CLICK, subMenu);
    exit_btn.removeEventListener(MouseEvent.CLICK, exitGame);
    removeChild(cursor);
     gotoAndStop('Sub Menu');
}
function exitGame(event:MouseEvent):void
{
     fscommand('ExitGame');
}

对于第二帧的 AS3:

play_btn.addEventListener(MouseEvent.CLICK, playGame);
back_btn.addEventListener(MouseEvent.CLICK, backBtn);

cursor = new cursor_mc();
addChild(cursor);
     cursor.x = mouseX;
     cursor.y = mouseY;
cursor.startDrag();
Mouse.hide();

function playGame(event:MouseEvent):void
{
     fscommand('PlayMap');
}
function backBtn(event:MouseEvent):void
{
    removeChild(cursor);
     gotoAndStop('Main Menu');
}

每次点击第 1 帧时都会实例化光标,我相信这会产生命名空间问题。解决方案是从舞台上移除光标,然后将其重新添加到每一帧。可能有一个更优雅的解决方案,但由于我从不使用 AS 的多个帧(出于这个原因),这是我能做的最好的。我还隐藏了鼠标光标以使您的 cursor_mc 更加集中。

如果您有任何其他问题,请告诉我。 编码愉快!

【讨论】:

  • 非常感谢!有趣的是,我在 UDK 中尝试了 swf,它运行良好,至少可以说很奇怪。不过答案很好。
  • 很高兴为您提供帮助,@Taslem!如果确实解决了问题,请将我的解决方案标记为答案。谢谢,祝您编码愉快!
【解决方案2】:

另一种解决方案是创建一个新层,并将光标代码仅放在该层上。该层将有一个关键帧,并扩展到覆盖整个时间轴,因此它始终处于活动状态。

或者,创建一个存在于第 1 帧上的菜单影片剪辑。在该影片剪辑中,为菜单的每个部分(选项等)设置不同的帧。并且光标将与菜单影片剪辑存在于同一级别。所以它一直存在,并且只初始化一次。

【讨论】:

    猜你喜欢
    • 2013-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多