gpt4 book ai didi

actionscript-3 - ActionScript 错误 1151 : randomly selected obstacle

转载 作者:行者123 更新时间:2023-12-04 17:03:56 25 4
gpt4 key购买 nike

我对 ActionScript 比较陌生,我试图选择一个随机选择的障碍物来飞向我的玩家角色。我不断收到错误 1151:与命名空间内部中的定义 obstInstance 存在冲突。我得到同样的错误三次。我认为这是因为我反复为相同的障碍实例分配新值(即使它在条件格式内)。任何帮助将不胜感激!

this.addEventListener(Event.ENTER_FRAME, obstacleGenerator);
function obstacleGenerator(e:Event):void
{
trace("Obstacle Generator Initiated");
var obstacleSelector:uint=Math.ceil(Math.random()*4);
trace("Obstacle Number ", obstacleSelector);

if (obstacleSelector==1){
var obstInstance:Obj1 = new Obj1();
}
else if (obstacleSelector==2){
var obstInstance:Obj2 = new Obj2(); //error 1151
}
else if (obstacleSelector==3){
var obstInstance:Obj3 = new Obj3(); //error 1151
}
else if (obstacleSelector==4){
var obstInstance:Obj4 = new Obj4(); //error 1151
}
}

最佳答案

您正在尝试为 4 个不同的对象提供相同的名称。每个都需要一个单独的名称。然后,您可以创建一个变量来保存 currentObject 并将其用作引用。

尝试

this.addEventListener(Event.ENTER_FRAME, obstacleGenerator);

var currentObj:Object;

var obstInstance1:Obj1;
var obstInstance2:Obj2;
var obstInstance3:Obj3;
var obstInstance4:Obj4;

function obstacleGenerator(e:Event):void
{

var obstacleSelector:uint=Math.ceil(Math.random()*4);


if (obstacleSelector==1){
setCurrentObj(obstInstance1 = new Obj1())
}
else if (obstacleSelector==2){
setCurrentObj(obstInstance2 = new Obj2())
}
else if (obstacleSelector==3){
setCurrentObj(obstInstance3 = new Obj3())
}
else if (obstacleSelector==4){
setCurrentObj(obstInstance4 = new Obj4())
}
}

function setCurrentObj(myObject:Object):void{
currentObj = myObject;
}

关于actionscript-3 - ActionScript 错误 1151 : randomly selected obstacle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21708945/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com