我是as3的新手,正在学习一些教程并编写了这段代码:
第1类(Enemy.as):
package
{
import flash.display.MovieClip;
public class Enemy extends MovieClip
{
public function Enemy()
{
x = 100;
y = 0;
}
public function moveDownABit():void
{
y = y + 3;
}
}
}
并在主类(AvoiderGame.as)中:
package
{
import flash.display.MovieClip;
public class AvoiderGame extends MovieClip
{
public var enemy:Enemy;
public function AvoiderGame()
{
enemy = new Enemy();
addChild( enemy );
}
}
}
我将我的Instant与它联系起来并且所有检查和工作。我也将主类添加到我的fla文件的Classdocument中,虽然我收到了这个错误:
C:\Users\x\Documents\Flash\tuts\game1- avoider\Classes\AvoiderGame.as, Line 2 1046: Type was not found or was not a compile-time constant: Enemy.
C:\Users\x\Documents\Flash\tuts\game1- avoider\Classes\AvoiderGame.as, Line 6 1046: Type was not found or was not a compile-time constant: Enemy.
任何想法?
答案 0 :(得分:0)
确保您的班级AvoiderGame和Enemy位于同一个包(文件夹)中,其文件名与班级名称相同(AvoiderGame.as& Enemy.as)。