您将该方法标记为static。这意味着它属于 class 本身而不是该类的 instances。
要调用定义的方法,你会说:
class_Object.spawn()
但是,这可能不是预期的,但是如果没有看到实现就很难说。从其定义中删除 static 关键字会将其附加到 instance 并且可以按照您描述的方式访问。
有关该主题的 adobe 文档,请参阅 here。
要回答您的评论,一种简单的思考方式是“类”是创建“实例”的蓝图。
所以,当您说new class_Object() 时,您是在告诉“蓝图”“构建”蓝图的一个新实例。在蓝图中,您可以定义实例(或实例方法)应该可用的方法/属性。此外,您还可以定义“蓝图”本身(或静态方法)可用的方法/属性。
所以使用Car的经典示例
public class Car {
public function startEngine():void {
// This is an instance method, it will be available to
// any instance of a car, or new Car();
// Note: "this" in this context refers to the current instance of the car
// that the method is being called from
}
public static function compare(Car car1, Car car2):bool {
// This method belongs to the blueprint of a car
// Note: "this" doesn't make any sense in this context, because we
// aren't talking about a particular instance.
}
}
那么例如:
var mercedes:Car = new Car();
var bmw:Car = new Car();
mercedes.startEngine(); // call an instance method. notice we call it from a particular instance of a car.
Car.compare(mercedes, bmw); // call an static method. notice we call it from the class of Car.
当您从另一个类“扩展”时,您是在从另一个类“借用”功能并添加/替换您自己的功能。但是,只要您有一个实例,如果它是一个“公共”方法,那么它就可以从该实例可用的任何地方从外部可用。我不知道这是否有助于回答您的评论。