'private属性只能用于类属性定义。 Flash CS5错误?

时间:2012-04-05 21:02:22

标签: actionscript-3

这是我的代码:

http://pastebin.com/nSkVkTJT

错误是第123行和第128行。

我已经用Google搜索了错误,但我仍然无法修复它,现在让我困惑了一个小时!我已经尝试添加花括号但仍然是同样的错误。

请帮助,谢谢!

我像这样离开第123和128行

    function _update(e:Event):void
    {
        _helicopter.update(_mouseDown);
    }

     function onEnterFrame(e:Event):void
    {'

但我收到一条错误,指出_update未定义

2 个答案:

答案 0 :(得分:0)

定义嵌套函数时,我不相信您可以指定访问修饰符。

public class X extends MovieClip
{

    public function f():void
    {
        /* illegal - nested function with private modifier not allowed */
        private function nested():void {};

        /* valid - nested function */
        function nested():void {};
    }

}

因此,如果您要在函数中定义函数,请删除private访问修饰符关键字并进行编译。

就个人而言,我建议将这些功能拉到主类定义的范围内。

答案 1 :(得分:0)

在您发布的代码中,您缺少2个尾随“}” 如果您更好地格式化代码,将会更容易找到。

private function onEnterFrame(e:Event):void{
  if (startme){
    x -= speed;
  }

  // make me start again when I go off-screen
  if (x < -42){
    speed = Math.floor(Math.random() * 9 + 5);
    height = Math.floor(Math.random() * 200 + 5);
    x = 551;
    if(updown == 2){
      y = 0;
    }else{
     y = 400 - height;
    }
  }// <------ you are missing this
}// <-------- you are missing this