actionscript-3 - 在 ActionScript 中,虚拟关键字有什么作用?

标签 actionscript-3

我发现一些将virtual关键字用于函数的代码,例如:

package tryOut{
    public class Parent {

        public function Parent() {}

        public function foo():void{
            trace("Parent foo");
        }//foo

        public virtual function bar():void{
            trace("Parent virtual bar");
        }//bar      
    }//class
}//package

据我了解,使用virtual关键字应该修改覆盖方法的工作方式,或者使用子方法的工作方式,等等。但是似乎它什么也没做。具有扩展性:
package tryOut {
    public class Child extends Parent {
        public function Child() {}

        public override function foo():void {
            trace("Child foo");
        }//foo

        public override function bar():void {
            trace("Child virtual bar");
        }//bar

    }//class
}//package

打印以下代码:
var parent:Parent = new Parent();
var child:Child = new Child();

parent.foo(); //Parent foo
child.foo(); //Child foo
parent.bar(); //Parent virtual bar
child.bar(); //Child virtual bar

var childCast:Parent = child as Parent;

parent.foo(); //Parent foo
childCast.foo(); //Child foo
parent.bar(); //Parent virtual bar
childCast.bar(); //Child virtual bar

因此,这两种方法在覆盖方面的作用相同。 virtual关键字是否会更改我所缺少的内容?

最佳答案

从帮助文档中(如果您使用的是Flash,请搜索“虚拟”):

There are also several identifiers that are sometimes referred to as future reserved words. These identifiers are not reserved by ActionScript 3.0, though some of them may be treated as keywords by software that incorporates ActionScript 3.0. You might be able to use many of these identifiers in your code, but Adobe recommends that you do not use them because they may appear as keywords in a subsequent version of the language.


abstract boolean byte cast

char debugger double enum

export float goto intrinsic

long prototype short synchronized

throws to transient type

virtual volatile

因此,在AS3中,虚拟绝对不执行任何操作。

关于actionscript-3 - 在 ActionScript 中,虚拟关键字有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2248745/

相关文章:

actionscript-3 - 变量的AS3对象表示法

actionscript-3 - Flash As3 流媒体播放器 - onBWDone

actionscript-3 - AS3 中的 get/set 方法和封装

apache-flex - 我可以使用哪些算法来计算音量?

xml - 使用 adobe air 保存 XML 文件会在开头创建虚假符号

Flash AS3 全局变量?

actionscript-3 - 通过 Actionscript 3.0 使用 HTTP POST 上传 zip 文件

flash - 我的 Flash 应用程序如何确定自己的 URL?

actionscript-3 - 间歇 #1034 类型强制转换失败 AS3

apache-flex - 大图片加载问题