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


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

  2. Keith

    ActionScript 3.0 中文档类要求代码和文档分离设计,所以将自定义的类放在独立的包(package)中,然后在包的同级目录下建立.fla文档,并在文档类输入文本框中输入正确的类路径,实现文档类的绑定.就不会出现1063的错误了.
    在文件夹lzxt下面建立AS 3.0类文件Test.as:(代码如下)
    package lzxt {
    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);

    private function test(evt:MouseEvent):void {



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


  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

添加新评论 »