AS3使默认数组起作用:函数示例(human:Array = ["heart","skull"])? [英] AS3 making a default array work: function example(human:Array = ["heart","skull"])?

查看:135
本文介绍了AS3使默认数组起作用:函数示例(human:Array = ["heart","skull"])?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此唯一可行的方法是:

So the only thing that seems to work is:

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语句是制作默认数组参数的唯一方法吗?

Is the if statement the only work around to making a default array parameter?

推荐答案

ActionScript仅允许将编译时常量(字符串,数字,int,null)作为默认参数.数组和对象实例不能为常量,因为它们是引用.因此,您不能将它们用作默认参数.

ActionScript only allows compile-time constants (string, number, int, null) as default parameters. Arrays and object instances cannot be constants because they are references. Hence, you cannot use them as default parameters.

这篇关于AS3使默认数组起作用:函数示例(human:Array = ["heart","skull"])?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆