jorrit5477
10-17-2007, 01:37 PM
Hi,
I am currently working on a game in which I have a central place for creating Entities, called EntityManager. This singleton class maintains a map (associative array) of references to all created Entities. These are created using the method
private var mEntities:Array;
public function createEntity(name:String):Entity
{
if (name && !mEntities[name])
{
var ent:Entity = new Entity(name);
mEntities[name] = ent;
return ent;
}
return null; // For clearance, would be better to throw an exception
}
It would make sense to me when I have a create operation, I als have a destroy operation, which would look like
public function destroyEntity(name:String):void
{
if (name)
{
var ent:Entity = mEntities[name];
delete mEntities[name]; // Clear the place in the map
// Make all references to the Entity invalid, but how???
}
}
How could I make all references to an object invalid? Calling a sort of destructor in which I call delete this, doesn't do the trick.
Can anybody point me the right direction?
Cheers!
I am currently working on a game in which I have a central place for creating Entities, called EntityManager. This singleton class maintains a map (associative array) of references to all created Entities. These are created using the method
private var mEntities:Array;
public function createEntity(name:String):Entity
{
if (name && !mEntities[name])
{
var ent:Entity = new Entity(name);
mEntities[name] = ent;
return ent;
}
return null; // For clearance, would be better to throw an exception
}
It would make sense to me when I have a create operation, I als have a destroy operation, which would look like
public function destroyEntity(name:String):void
{
if (name)
{
var ent:Entity = mEntities[name];
delete mEntities[name]; // Clear the place in the map
// Make all references to the Entity invalid, but how???
}
}
How could I make all references to an object invalid? Calling a sort of destructor in which I call delete this, doesn't do the trick.
Can anybody point me the right direction?
Cheers!