Class Enter Frame Problem
Hello,
I am trying to make a simple game where an enemy chases the player if they get to close, and stops if the player moves a certain distance away.
I have a script for the enemy that looks like this :
------------------------------------------------------------------------------------------------------------------------------------------------
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.geom.Point;
public class Enemy extends MovieClip
{
var positionX:int;
var positionY:int;
public function Enemy()
{
addEventListener(Event.ENTER_FRAME, enemyChase);
}
public function setPosition (playerX:int, playerY:int)
{
positionX = playerX;
positionY = playerY;
}
public function enemyChase (event:Event):void
{
var des:Point = new Point(positionX, positionY);
var loc:Point = new Point(x, y);
var speed:Number = 1
if (((Math.abs(positionX - x)) < 90) && ((Math.abs(positionY - y)) < 90))
{
var vel:Point = des.subtract(loc);
vel.normalize( speed );
x += vel.x;
y += vel.y;
}
}
}
}
------------------------------------------------------------------------------------------------------------------------------------------------
In my Main script I create a variable of the Enemy class like so :
var enemyScript:Enemy = new Enemy();
and on the Enter Frame function in the Main script I update the player's position for the Enemy class, like so :
enemyScript.setPosition (player.x, player.y);
However it isn't working. If I put something small into the Enemy class Enter Frame function like :
x += 1;
Then the enemies on the screen move every frame, so I know the class is linked properly. And I'm not getting any errors when I compile. What am I missing?
Thanks
P.S. the enemyChase function works when I put it in the Main function and link it directly using instance names, it's just getting it to work from a different class that's the problem