所以似乎唯一有效的是:
function example(human:Array = null)
{
if (human == null)
human = ["heart","skull"]
}
为什么我能做到:
function example(human:String = "Heart"){}
function example(human:Number = 1){}
但是
function example(human:Array = ["Heart","Chest"])
给我:
Scene 1, Layer 'Layer 1', Frame 1, Line 1 1047: Parameter initializer unknown or is not a compile-time constant.
if 语句是创建默认数组参数的唯一解决方法吗?
最佳答案
ActionScript 只允许编译时常量(字符串、数字、int、null)作为默认参数。数组和对象实例不能是常量,因为它们是引用。因此,您不能将它们用作默认参数。
关于arrays - AS3 使默认数组工作 : function example(human:Array = ["heart" ,"skull"])?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31307707/