So I am making a tower defense game that has a unit that acts as a mobile tower. My other towers also have a Sell feature. When I sell a tower it seems to be interrupting my Keyboard listners and this causes my mobile tower either no be moveable or he runs off screen. I have a key class that handles my Keyboard listeners and a function (isDown) that checks if the key is down from an array. Anyway when I sell a tower I perform a removeChild(t) from my movie clip that handles all of my towers and this causes my keyboard listeners to malfunction. Could anyone explain why?
// Let’s clean up dead Towers
for (var i:int = 0; i < this.mTowers.length; i++)
{
var t:Tower = this.mTowers*;
if (t.IsDestroyed())
{
//this.mTowerMC.removeChild(t); <–This line causes the issue.
this.mTowers.splice(i, 1);
}
}
I forgot to mention that the Keylisteners are added within the fla and the mobile tower is not part of that mTowerMC movieclip.