Reputation: 11
I'm making a flash AS3 platformer game, but actually after adding the "bullets" (shots) in a new class system (I didn't use classes until then), I have an error that I couldn't resolve at all : TypeError: Error #1010: A term is undefined and has no properties.
Now, I know this is a common error implying variables values, but I really couldn't tell where it came from.
The problem showed up when I added this to my main timeline code :
function Shoot():void {
var directionPerso:String;
if(perso.scaleX < 0){
directionPerso = "gauche";
} else if(perso.scaleX > 0){
directionPerso = "droite";
}
var tir:rayon = new rayon(perso.x - scrollX, perso.y - scrollY, directionPerso);
stage.addChild(tir);
}
And this one is for the my class file :
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.display.Sprite;
public class rayon extends MovieClip{
private var vitesse:int = 10; //Vitesse du déplacement du rayon, fonction privée car tout le programme n'a pas besoin de connaitre cette valeur
private var xInitial:int;
public function effacer():void
{
removeEventListener(Event.ENTER_FRAME, loop);
this.parent.removeChild(this);
}
public function rayon(persoX:int, persoY:int, directionPerso:String) {
// constructor code
if(directionPerso == "gauche") { //Ce qui se passe si la direction du joueur est "gauche", la balle part de la position du joueur, à gauche
vitesse = -10;
x = persoX - 25;
}
else if(directionPerso == "droite") { //Ce qui se passe si la direction du joueur est "droite", la balle part de la position du joueur, à droite
vitesse = 10;
x = persoX + 25
}
y = persoY - 75;
xInitial = x;
addEventListener(Event.ENTER_FRAME, loop); //Toujours pour avoir un programme bien plus fluide
}
public function loop(e:Event):void{ //Dans une nouvelle fonction publique je crée le mouvement du rayon, relatif à la variable de vitesse créée plus haut
x += vitesse;
if(vitesse > 0) { //Si le rayon va vers la droite
if(x > xInitial + 450) { //Le tir disparait au bout de 450px
effacer();
}
} else {
if(x < xInitial - 450) { //Quand la cartouche va vers la gauche...
effacer(); //Elle disparait au bout de 450px
}
}
}
Can someone help me with this? Thank you!
Upvotes: 1
Views: 91
Reputation: 4306
The best way to troubleshoot this is to go to the Publish Setting and check the "Permit Debugging" option. This will append the line number where the error occurred to the output so you can track it down easier.
However, without knowing more about the setup my guess would be that you don't have the variable "perso" or maybe "scrollX/scrollY" defined.
Upvotes: 1