Flash / Actionscript预加载器和按钮onRelease问题

时间:2011-05-05 12:42:30

标签: flash actionscript flash-cs5

使用此作为预加载器的动作脚本:

if(_root.getBytesLoaded() != _root.getTotalBytes()) {
    gotoAndPlay(1);
}

收到错误:

Scene 1, Layer 'Actions', Frame 2, Line 1   1120: Access of undefined property _root.

这是我的按钮动作:

    stop();
home_btn.onRelease = function () {
    gotoAndStop(3);
}
page1_btn.onRelease = function (){
    gotoAndStop(4);
}
page2_btn.onRelease = function (){
    gotoAndStop(5);
}

和错误:

Scene 1, Layer 'Actions', Frame 3, Line 2   1119: Access of possibly undefined property onRelease through a reference with static type fl.controls:Button.

我喜欢让我的网站运转起来。你能帮帮我们吗? 我错了什么?我喜欢使用最新的动作。

1 个答案:

答案 0 :(得分:2)

以下是您的代码直接转换为AS3:

第2帧:

if (root.loaderInfo.bytesLoaded != root.loaderInfo.bytesTotal) {
     gotoAndPlay(1);
}

第3帧:

stop();

home_btn.mouseChildren = page1.mouseChildren = page2.mouseChildren = false;
home_btn.addEventListener(MouseEvent.CLICK, clickHandler);
page1_btn.addEventListener(MouseEvent.CLICK, clickHandler);
page2_btn.addEventListener(MouseEvent.CLICK, clickHandler);

function clickHandler(e:MouseEvent):void {
     switch(e.target) {
          case home_btn : gotoAndStop(3); break;
          case page1_btn : gotoAndStop(4); break;
          case page2_btn : gotoAndStop(5); break;
     }
}

据说......我建议不要这样加载你的资产。我会创建一个“shell”SWF加载这个“主”SWF。这将为您提供更准确的负载。此外,如果您还没有,请开始考虑将您的代码从时间线上移到外部类(如果您计划使用AS3)。 AS3是一种面向对象的编程语言,旨在以这种方式使用。你现在拥有的是什么,但学习这种方法可以为你节省很多麻烦。这是一个很好的起点:http://www.adobe.com/devnet/actionscript/articles/oop_as3.html