戦闘機と弾丸には配列を使用します
package {
import flash.display.MovieClip;
import flash.events.Event;
public class level extends MovieClip {
var fighters:Array;
var bullets:Array;
public function level() {
trace("level");
addEventListener(Event.ENTER_FRAME, loop);
bullets=new Array();
fighters=new Array();
}
function loop(e:Event) {
if(numChildren<3) {
var f=new fighter();
addChild(f);
// fighter spaWNS RANDOMLY
f.x=Math.random()*stage.stageWidth;
f.y=Math.random()*stage.stageHeight;
f.rotation=Math.random()*360;
fighters.push(f);
}
for(var bcount=bullets.length-1; bcount>=0; bcount--) {
bullets[bcount].update();
if(bullets[bcount].parent==null) {
bullets.splice(bcount,1);
bcount--;
}
}
for(var count=fighters.length-1; count>=0; count--) {
//**** error is here
//**** there is a mismatch in the arguments with the fighter
fighters[count].update();
for(bcount=bullets.length-1; bcount>=0; bcount--) {
if(fighters[count].hitTestObject(bullets[bcount])) {
fighters[count].health--;
removeChild(bullets[bcount]);
bullets.splice(bcount,1);
}
}
if(fighters[count].health<=0) {
removeChild(fighters[count]);
fighters.splice(count,1);
}
}
}
}
}