【发布时间】:2012-10-27 05:15:18
【问题描述】:
我的问题是这样的问题:ArgumentError: Error #1063
不同之处在于,在我的文档类加载后我得到了这个错误,我点击了一个按钮来启动 Game() 类。 PowerUp() 类会自动生成错误,而不会被程序调用。我发现 PowerUp() 类构造函数中的第一个参数没有接收到值。
public function PowerUp(tar:Object,s:Number=1, a:String="bonusShots",t:String="Multi Shot", l:int=100):void {/// 更多代码
我需要将舞台上的影片剪辑“thePlayer”放入 PowerUp() 类构造函数的第一个参数中。
当我将“thePlayer”添加到构造函数中时,我得到另一个错误“object not a compile time constant”。
var thePlayer: MovieClip=thePlayer;公共函数 PowerUp(tar:Object=thePlayer,s:Number=1, a:String="bonusShots",t:String="Multi Shot", l:int=100):void {/// 更多代码
问题:如何将“thePlayer”电影剪辑合并到 PowerUp 类的构造函数中?
这是 PowerUp 类的代码
public class PowerUp extends Sprite{
protected var type:String;// type of power up
protected var strength:Number;// power of power up
protected var attribute:String;// attribute effected by power up
protected var target:Object;// target to buff/boost/perk up/ empower/improve/enhance
protected var lifespan:int;// the life span of a perk
protected var maxLifeSpan:int; // max time to live grahic
const BAR_WIDTH=100;// width of rect
const BAR_HEIGHT=15;// height of rect
public function PowerUp(tar:Object,s:Number=1, a:String="bonusShots",t:String="Multi Shot", l:int=100):void {
type=t;
strength=s;
attribute=a;
target=tar;
lifespan=l;
maxLifeSpan=l;
perkName.text=t;
perkName.blendMode="invert";
// apply perk to target
target[attribute]+=strength;
}// end constructor
【问题讨论】:
-
您在舞台上的某个地方有 PowerUp 资产实例吗?如果是,则使用 0 参数对其进行初始化。检查这一点:将默认值添加到“tar”参数:
public function PowerUp(tar:Object=null,...并将跟踪语句放入构造函数中。也添加一个空保护:if (!tar) return;并检查运行 SWF 时出现了多少跟踪。 -
谢谢,if(!tar) 返回;工作!
标签: actionscript-3 flash compiler-errors