[英]ReferenceError: Error #1069 Actionscript 3
So i have been stuck on this for about 2 weeks and i have no idea how to progress. 所以我已经坚持了大约2周,我也不知道该如何进步。
I have an array of movie clips called "_main.speederArray" and i'm trying to make it so that if they collide with each other then they are both destroyed. 我有一个名为“ _main.speederArray”的电影剪辑数组,我正在尝试制作,这样如果它们相互碰撞,则它们都会被破坏。 Here is my code in the "Speeder class" to detect collision.
这是我在“ Speeder类”中用于检测碰撞的代码。
private function detectionHandler():void{
//trace("array length", _main.speederArray.length);
detectionID = _main.gameCounter;
for ( var i:int = _main.speederArray.length -1; i >= 0; i--){
var speeder:Speeder = _main.speederArray[i];
if(speeder.destroyMe) continue;
if(speeder.detectionID == this.detectionID) continue;
if (boxIntersect(this, speeder)){
trace("collision");
destroyMe = true;
speeder.destroyMe = true;
}
}
}
Here is the boxIntersect function this code refers to. 这是此代码引用的boxIntersect函数。 It's in the same class
在同一班
private function boxIntersect ( speeder1:Speeder, speeder2:Speeder):Boolean{
if(speeder1.x + speeder1.distRight < speeder2.x + speeder2.distLeft) return false; //checking for overlap on X axis
if(speeder1.x + speeder1.distLeft > speeder2.x + speeder2.distRight) return false;
if(speeder1.y + speeder1.distBot < speeder2.y + speeder2.distTop) return false; // checking for overlap on Y axis
if(speeder1.y + speeder1.distTop > speeder2.y + speeder2.distBot) return false;
return true;
}
And then here is where i think the problem is. 然后这就是我认为问题所在。 I have a class called "spawner" and this is where i was going to handle the objects being created and destroyed.
我有一个名为“ spawner”的类,这是我要处理正在创建和销毁的对象的地方。 Here is the code where i am trying to splice objects from the array depending on whether the destroyMe bool is set to true.
这是我要根据是否将destroyMe bool设置为true来从数组中拼接对象的代码。 At this stage i have confused the shit out of myself so any help would be greatly appreciated!
在这个阶段,我已经把自己弄糊涂了,所以任何帮助将不胜感激!
private function updateArray(e:Event):void{
for(var i:int = _main.speederArray.length - 1; i>=0; i--){
var speeder:Speeder = _main.speederArray[i];
if(speeder.destroyMe){
//trace("hello");
removeChild(speeder[i]); // take it off the stage
_main.speederArray[i] = null;
_main.speederArray.splice(i, 1); //remove it from the array
}
}
}
Now, the game runs however as soon as the 2 objects within the same array collide, i get the collision trace in the output window but straight after i get this : 现在,游戏开始运行,但是只要在同一数组中的2个对象发生碰撞,我就会在输出窗口中获得碰撞轨迹,但是在得到以下结果后立即可以:
ReferenceError: Error #1069: Property 1 not found on com.game.Speeder and there is no default value. ReferenceError:错误#1069:在com.game.Speeder上找不到属性1,并且没有默认值。 at com.game::Spawner/updateArray()
在com.game::Spawner/updateArray()
No idea what it means :( 不知道是什么意思:(
Any help appreciated thanks guys! 任何帮助表示感谢,谢谢大家!
The problem comes from the line removeChild(speeder[i]);
问题来自于
removeChild(speeder[i]);
inside your update function. 在您的更新功能中。 Speeder has no properties that are called
1
and the 1 comes obviously from your for loop. Speeder没有被称为
1
属性,而1显然来自您的for循环。
So, to solve this problem, you should simply call 因此,要解决此问题,您只需致电
removeChild(speeder);
speeder
already is the object at the position i
of your array. speeder
已经是数组i
上的对象。 Putting [] behind an object is the same like accessing a property from it. 将[]放在对象后面就像从其访问属性一样。 essentially you were doing this:
本质上,您正在这样做:
removeChild(speeder.1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.