You can get all entities with
var spikes:Array = new Array();
world.getType("spike", spikes);
Then puts all spikes into the “spikes array”
then you can check for ID’s by using that when switch key used to call switch() function of spikes
for each (var spike:Spike in spikes)
{
if(spike.ID == "1")
{
spike.switch();
}
}
spikes.length = 0;
that should work for you, but that’s not the efficient way to do this. that creates that array everytime and that’s not cool
so it’s better you create a
public var spikesList:Array = new Array();
in your “main world class(so you can reach it easy)”
and you can add your spikes to this array when they created at the beginning of level by using spikes’ added function
override public function added():void
{
this.world.spikesArray.push(this);
}
that works faster then other way. Don’t forget to clear array with “spikesArray.length = 0” when any world is closed(override end() function) because of that variable belongs to main world class. Then now you can make your switchers’ switch functions look like this
for each (var spike:Spike in this.world.spikesArray)
{
if(spike.ID == "1")
{
spike.switch();
}
}
if you have tooooo many spikes with different ID’s, you can try to create different arrays inside a dictionary variable in world class by this way to make so much better performance, but it’s not neccessary if you don’t have hundreds