我目前正在尝试创建一个小应用程序时遇到问题,这是我第一次尝试处理类,但由于某种原因,即使它已导入文档,我也无法创建该类的任何实例。这是该类的代码(名为“Players”):
package
{
public class Player
{
public function Player(name_:String)
{
}
public var name_:String;
private var alignment:int;
public var healed:Boolean = false;
public var revealed:Boolean = false;
public var attacked:Boolean = false;
public var dead:Boolean = false;
public function action(target:Player)
{
}
public function describe():String
{
}
}
public class Citizen extends Player
{
public function Citizen(name_:String)
{
alignment = 1;
}
override public function action(target:Player)
{
}
override public function describe():String
{
return "Citizen";
}
}
public class Investigator extends Player
{
public function Investigator(name_:String)
{
alignment = 1;
}
override public function action(target:Player)
{
target.revealed = true;
}
override public function describe():String
{
return "Cop";
}
}
public class Doctor extends Player
{
public function Doctor(name_:String)
{
alignment = 1;
}
override public function action(target:Player)
{
target.healed = true;
}
override public function describe():String
{
return "Doctor";
}
}
public class Mafioso extends Player
{
public function Mafioso(name_:String)
{
alignment = -1;
}
override public function action(target:Player)
{
target.attacked = true;
}
override public function describe():String
{
return "Mafia";
}
}
}
以及创建实例的代码:
导入玩家;
stop();
var totalplayers:Number;
var playerArray:Array = new Array();
var playerType:Array = ["Citizen","Cop","Doctor","Mafia"];
var test:Citizen = new Citizen("James");
两者都在同一个文件夹中。我得到了标题中描述的错误代码 1046,但老实说,我不知道为什么,flash 在代码提示中找到了它,但它却出现了!任何帮助,将不胜感激。
也是次要问题,我永远不会启动 Player 类(除非通过与其他类的继承),所以我可以将其设为私有吗?
谢谢