开发者

AS4 Flash Importing Custom Classes

I am trying to import classes to no avail.

test.fla

timeline 1: var main:Main = new Main();

main.as

package{  
    import flash.display.MovieClip;   
    public class Main extends MovieClip{  
        public function Main()  
        {  
            var _myClass:myClass;//this line will fail  
            trace("Main");    
        }
    }  
}  

myClassFile.as

package{   
   public class myClass   
   {  
       public function myClass()  
       {  
           trace("myClass");  
       }  
   }   
} 

Error: 1046: Type was not found or was not a compile-time constant: myClass.

//lets try this . . .

main.as

package{   
    import flash.display.MovieClip;   
    import MyPackage;  
    public class Main extends MovieClip{  
        public function Main(){  
            var _myClass:myClass;  
            trace("Main");    
        }  
    }
}

myClassFile.as开发者_Python百科

package MyPackage{    
    public class myClass {  
        public function myClass(){  
            trace("myClass");  
        }  
    }   
}

Error: 1172: Definition MyPackage could not be found.

All files are located in the same directory


Soluition: rename the class to reflect the name of the file

myClassFile.as

package{  
  public class myClassFile  
  {  
   public function myClassFile()  
   {  
   trace("myClassFile");  
   }  
  }  
} 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜