No idea what I’m doing wrong here, it just won’t let me access any of my public methods on my class. I just keep getting “Error 1180: call to a possibly undefined method”!
If I run the same function in the constructor of the class everything is fine.
package main{
import flash.display.Sprite;
import sat.SAT;
public class Game extends Sprite
{
public var sat:SAT = new SAT(this);
public function Game()
{
trace(this+" initalized");
sat.start(); // !!! this doesn't work !!!
}
}
}
package sat{
import flash.events.Event;
public class SAT extends Object
{
private var parent;
// 2 arrays are used in tandem
private var satArray:Array = [];
private var objArray:Array = [];
public function SAT(parent)
{
trace(this+" initalised");
this.parent = parent;
// start(); // !!! ...but this works fine! !!!
}
public function addObj(satObj, gfxObj):void
{
satArray.push(satObj);
objArray.push(gfxObj);
}
public function start():void
{
parent.addEventListener(Event.ENTER_FRAME, checkCollisions);
}
public function stop():void
{
parent.removeEventListener(Event.ENTER_FRAME, checkCollisions);
}
public function checkCollisions(e:Event)
{
trace("working");
for (var i:uint = 0; i < satArray.length; i++)
{
for (var j:uint = i+1; j < satArray.length; j++)
{
var collision = Collision.test(satArray*, satArray[j]);
if (collision)
{
trace("collision "+objArray*);
trace("collision "+objArray[j]);
if ("handleCollision" in objArray*) objArray*.handleCollision(collision);
if ("handleCollision" in objArray[j]) objArray[j].handleCollision(collision);
}
}
}
}
}
}
Can anybody see any problem with this?