I am new to Actionscript 3.0 and I’m currently trying to replicate the usage of attachMovie(), and removeMovieClip() from AS 2.0.
So far I have gotten things working using addChild() and removeChild(), but there is an error message that comes up in the output window that I have a question about.
Here is my code, it is in the main timeline.
bullets is the array that holds all of the bullets created, and BulletClass is the name of the bullet movieclip’s class in linkage.
var bullets:Array = new Array();
function shootWeapon():void{
var newbullet:BulletClass = new BulletClass();
addChild(newbullet);
bullets.push(newbullet);
newbullet.x = 0;
newbullet.y = 300;
}
addEventListener(Event.ENTER_FRAME,OEF);
function OEF(Event){
for(var i:uint = 0;i<bullets.length;i++){
bullets*.x += 10;
if(bullets*._x >= 500){
removeChild(bullets*);
bullets.splice(i,1);
}
}
}
shootWeapon();
This works the way I want it to, creating bullets with shootWeapon(), moving them to the right, and removing them from the array and the screen when they get past 500 x.
But, I get this error in the output window when one of the bullets gets removed.
TypeError: Error #1010: A term is undefined and has no properties.
This error doesn’t prevent me from compiling, and only shows up in the output window. But I would like to know: What does this error mean, is it important, how do I get rid of it, and is there a better way of removing these bullets from both the array and the screen? Help would be appriciated.