Flash AS 疑难问题悬赏:1037: Packages cannot be nested.


1037: Packages cannot be nested.
package {

上面是我编译一点代码时出现的错误信息,现在还没有解决办法。 :(

网上也还没有找到解决方案,只找到一段类似的,说是 自定义的Class,必须放在外部as文件中。
我也依照如此修改。但是还是得到这样的错误提示。

不知道我又犯了什么很简单但又很愚蠢的问题,麻烦又知道的朋友给俺说一声。

又错误详细描述:
编译窗口出现的信息内容:

Script-1.as,Line 1 1037: Packages cannot be nested. package {

我检测过语法,没有任何错误。

  1. Keith

    然后在lzxt的同级目录下创建flash文档.fla,并在文档类输入文本框中输入"lzxt.Test"实现文档类的绑定,按下"Ctr+Enter"编译文件,则不会再出现1063的错误.

    1. 感谢啊,谢谢分享给老周!
      我懂了! :)

  2. Keith

    ActionScript 3.0 中文档类要求代码和文档分离设计,所以将自定义的类放在独立的包(package)中,然后在包的同级目录下建立.fla文档,并在文档类输入文本框中输入正确的类路径,实现文档类的绑定.就不会出现1063的错误了.
    例如:
    在文件夹lzxt下面建立AS 3.0类文件Test.as:(代码如下)
    //定义包路径
    package lzxt {
    //导入包Sprite
    import flash.display.Sprite;
    //创建类
    public class Test extends Sprite {

    //构造函数 public function Test() { //创建对象 var sp:Csp = new Csp(); //加入对象 addChild(sp); }

    }
    }
    //包外类,用于创建对象
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    class Csp extends Sprite {
    public function Csp() {

    //使用绘制方法绘制圆形 graphics.beginFill(0xff0000); graphics.drawCircle(100,100,20); graphics.endFill(); //注册CLICK事件侦听器 addEventListener(MouseEvent.CLICK,test);

    }
    //创建CLICK事件侦听函数
    private function test(evt:MouseEvent):void {

    trace("你单击以对象!");

    }
    }

  3. package文件放到外部导入,参考这个:

    http://www.flashforum.dk/forum/viewtopic.php?p=9581

  4. baohan

    To include ActionScript code, you reference an external ActionScript file in your tags. At compile time, the compiler copies the entire contents of the file into your MXML application, as if you had actually typed it. As with ActionScript in an block, ActionScript in included files can only consist of variable declarations if outside functions. Included files can also declare constants and namespaces, include other ActionScript files, import declarations, and use namespaces. You cannot define classes in included files.

    Variables and functions defined in an included ActionScript file are available to any component in the MXML file. An included ActionScript file is not the same as an imported ActionScript class. Flex provides access to the included file's variables and functions, but does not add a new class, because the MXML file itself is a class.

    在手册的目录中有详细的解说

    Flex 2 Developer's Guide > Using Flex Programming Languages > Using ActionScript > Comparing, including, and importing ActionScript code

添加新评论 »

captcha