對於我在Flash中的第一個項目,我決定製作一個小型足球比賽。每當我確定每個單獨的對象時它都在工作,但是因爲我想添加更多的小AI玩家,所以我嘗試使運動與包含對象的一些陣列一起工作,但是隨後它返回了此錯誤消息。任何幫助?ActionScript 3.0錯誤#1009:無法訪問空對象引用的屬性或方法
function movers(event:Event):void
{
for (var qwerty:int=0;qwerty<=(ALIEN.length);qwerty++) {
var run:Object=ALIEN[qwerty];
run.rotation=Math.atan2(bc.y-run.y,bc.x-run.x)/(Math.PI/180);
run.x+=Math.cos(sym.rotation*Math.PI/180)*SPD;
run.y+=Math.sin(sym.rotation*Math.PI/180)*SPD;
}
if (ftblFLY) {
ftbl.x+=Math.cos(ftbl.rotation*Math.PI/180)*7;
ftbl.y+=Math.sin(ftbl.rotation*Math.PI/180)*7;
}
for (var wer:int=0;wer<=(team.length);wer++) {
if (ftbl.hitTestObject(wer)) {
if (wer!=bc) {
bc=wer;
ftblFLY=false;
}
}
}
if (bc!=wr) {
wr.x+=Math.cos(wr.rotation*Math.PI/180)*SPD;
wr.y+=Math.sin(wr.rotation*Math.PI/180)*SPD;
}
for (var asdf:int=0;qwerty<=(ALIEN.length);asdf++) {
var runner:Object=ALIEN[asdf];
if (runner.hitTestObject(bc)) {
stage.removeEventListener(Event.ENTER_FRAME,movers);
stage.removeEventListener(KeyboardEvent.KEY_DOWN,keyers);
stage.removeEventListener(MouseEvent.CLICK,clicko);
texter.text="Tackled!!!";
}
}
bc.x+=Math.cos(bc.rotation*Math.PI/180)*(SPD*playaRD);
bc.y+=Math.sin(bc.rotation*Math.PI/180)*(SPD*playaRD);
bc.rotation=bc.rotation+(turno*playaTD);
ftbl.rotation=bc.rotation;
ftbl.x=bc.x;
ftbl.y=bc.y;
if (bc.y<=0) {
stage.removeEventListener(Event.ENTER_FRAME,movers);
stage.removeEventListener(KeyboardEvent.KEY_DOWN,keyers);
stage.removeEventListener(MouseEvent.CLICK,clicko);
texter.text="Touchdown!!!";
}
}
您應該進入fla發佈設置並單擊複選框以啓用調試。這樣,當您收到錯誤消息時,它會直接指向發生錯誤的行號。因爲這一切看起來像時間線代碼,並且這些對象中的許多*可能是舞臺上的動畫片段或按鈕,只是簡單的代碼檢查可能會或可能不會發生什麼是空的......可能是因爲您正在嘗試引用一個當時不存在的剪輯(不管你是否認爲它是)。所以得到具體的線路號碼,如果還不清楚,請回來發佈。 – scriptocalypse 2011-03-26 14:43:30