0
我正在嘗試製作一款遊戲,涉及到一名燃燒小騎士的龍,相當簡單,但我是新來的AS3,似乎無法解決這個問題,有時當我殺死一名騎士時,它會返回一個輸出錯誤說: TypeError:錯誤#1010:一個術語未定義,並沒有任何屬性。 at drogtor/onTick()TypeError:錯誤#1010:術語未定義且沒有屬性。成功移除對象的問題
我在本網站的其他地方找不到任何相關解決方案,所以我自己提交了一個問題。
這是(我認爲是)的相關代碼。
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.KeyboardEvent;
import global;
import flash.display.DisplayObject;
public class drogtor extends MovieClip
{
private var updown:Boolean=true;
private var fArray:Array;
private var eArray:Array;
var wpressed:Boolean = false;
var apressed:Boolean = false;
var dpressed:Boolean = false;
var spressed:Boolean = false;
var kspawn:Number = 5;
public function drogtor()
{
addEventListener(Event.ENTER_FRAME, onTick);
stage.addEventListener(KeyboardEvent.KEY_DOWN, fliy);
stage.addEventListener(KeyboardEvent.KEY_UP, fliy);
fArray = new Array();
eArray = new Array();
}
public function onTick(e:Event):void
{
var fcount:int=0;
var sdargon:int=10;
var rdargon:int=6;
var Angle:Number = (2 * Math.PI * (dargon.rotation/360));
var dy:Number = sdargon * Math.cos(Angle);
var dx:Number = sdargon * Math.sin(Angle);
HitBox.x = dargon.x;
HitBox.y = dargon.y;
HitBox.rotation = dargon.rotation;
//Flame Spewer
if (global.count==9)
{
var fAngle:Number = (2 * Math.PI * (dargon.rotation/360));
var fdy:Number = 10 * Math.cos(fAngle);
var fdx:Number = 10 * Math.sin(fAngle);
var ftemp:Flame=new Flame;
ftemp.x=dargon.x + (10 * fdx);
ftemp.y=dargon.y - (10 * fdy);
ftemp.rotation=dargon.rotation + Math.random() * (15-(-15)) + (-15);
fArray.push(ftemp);
addChildAt(ftemp, 0);
}
var kgen:int = Math.floor((Math.random() * 3)+1);
var stageside:int = Math.floor((Math.random() * 4)+1)
if (kgen == 1)
{
if (Math.floor((Math.random() * 100) + 1) <= kspawn)
{
var ktemp:keniget = new keniget;
if (stageside == 1)
{
ktemp.x = Math.random() * stage.stageWidth;
ktemp.y = 0
}
else if (stageside == 2)
{
ktemp.x = Math.random() * stage.stageWidth;
ktemp.y = stage.stageHeight;
}
else if (stageside == 3)
{
ktemp.x = 0;
ktemp.y = Math.random() * stage.stageHeight;
}
else if (stageside == 4)
{
ktemp.x = stage.stageWidth;
ktemp.y = Math.random() * stage.stageHeight;
}
eArray.push(ktemp);
addChildAt(ktemp, 0);
}
}
for (var iKl:int = eArray.length-1; iKl >= 0; iKl --)
{
var krotation:Number = (Math.atan2(eArray[iKl].y-dargon.y, eArray[iKl].x-dargon.x) * 180/Math.PI) - 90;
eArray[iKl].rotation = krotation
var kangle:Number = (2 * Math.PI * (eArray[iKl].rotation/360));
var edx:Number = 3 * Math.sin(kangle);
var edy:Number = 3 * Math.cos(kangle);
eArray[iKl].x += edx;
eArray[iKl].y -= edy;
if (eArray[iKl].hitTestObject(HitBox))
{
removeChild(eArray[iKl]);
eArray.splice(iKl, 1);
}
for (var iF:int=fArray.length-1; iF>=0; iF--)
{
if (eArray[iKl].hitTestObject(fArray[iF]))
{
removeChild(eArray[iKl]);
eArray.splice(iKl, 1);
kspawn += 0.5
}
}
}
for(var iFl:int=fArray.length-1; iFl>=0; iFl--)
{
if(fArray[iFl].currentFrame==fArray[iFl].totalFrames)
{
removeChild(fArray[iFl]);
fArray[iFl]=null;
fArray.splice(iFl, 1);
}
}
if(updown)
{
dargon.rotationX-=1;
if(dargon.rotationX == -10)
{
updown = false;
}
}
if(!updown)
{
dargon.rotationX+=1;
if(dargon.rotationX == 10)
{
updown = true;
}
}
//Movement
if(wpressed)
{
dargon.x += dx;
dargon.y -= dy;
}
if(apressed)
{
dargon.rotation -= rdargon;
}
if(dpressed)
{
dargon.rotation += rdargon;
}
if(spressed)
{
dargon.x -= ((1/4) * dx);
dargon.y += ((1/4) * dy)
}
}
public function fliy(ke:KeyboardEvent):void
{
if(ke.type == "keyDown")
{
//key=A
if(ke.keyCode==87)
{
wpressed=true;
}
//Key=A
if(ke.keyCode==65)
{
apressed=true;
}
//Key=D
if(ke.keyCode==68)
{
dpressed=true;
}
if(ke.keyCode==83)
{
spressed=true;
}
}
if(ke.type == "keyUp")
{
//key=A
if(ke.keyCode==87)
{
wpressed=false;
}
//Key=A
if(ke.keyCode==65)
{
apressed=false;
}
//Key=D
if(ke.keyCode==68)
{
dpressed=false;
}
if(ke.keyCode==83)
{
spressed=false;
}
}
}
}
}
對不起AS3的新功能,但如何檢查騎士的引用是否爲空? – user3478914