Hello,
I would appreciate any help that I can receive with my issue. I will explain the circumstances then ask what to do.
I have 2 classes:
bullet class:Extends MovieClip and stores information about bullets while handling their movement and properties.
enemy class:Extends MovieClip and simply so far stores the x,y co-ordonates of the enemy.
I want the bullet to home onto the enemy object in the movement function by referencing the x and y position of the enemy.
Here’s the code:
**//Main as3 file
**
stage.addEventListener(MouseEvent.MOUSE_DOWN,clk);//stuff that happens on click
function clk (e:MouseEvent){
shotcnt += 1;
shotobj.push(new pshot(player.x,player.y));
addChild(shotobj[shotcnt]);
shotobj[shotcnt].addEventListener(Event.ENTER_FRAME,shotobj[shotcnt].movement);
}
**//pshot class file**
package {
import flash.display.MovieClip;
public class pshot extends MovieClip {
public var xvel =0;
public var yvel =0;
public var sped = 10;
public function pshot(mox, moy) {
// constructor code
this.x = mox;
this.y = moy;
this.yvel = ((mouseY)) / Math.sqrt( Math.pow(mouseY,2) + Math.pow(mouseX,2) )
this.xvel = ((mouseX)) / Math.sqrt( Math.pow(mouseY,2) + Math.pow(mouseX,2) )
}
public function movement(e:String)
{
var ex = enemy.x;**//this is where I get the error because i can't access the enemy object. I also tried stage.enemy.x and it failed too.**
this.x += sped*this.xvel;
this.y += sped*this.yvel;
}
}
}
Please help me allow my shot to reference the enemy object.
Thanks so much
-Taloton