Crappy actionscript bug

Alright, I’m working on the AI of my game. I’ve thought up a specific system that should work perfectly.

I have an AI object, that object has several objects among those are tankTeam and buildTeam.

When the AI builds a new tank or builder references of the objects are added to the tankTeam and buildTeam.

Now here is the strange thing, builders are just… not there…

Here’s some code of the ai class:


if (type == "tank")
            {
            team = whatNeedsResupplyMost();
            team.addUnit ( new Tank (factory.xTarget, factory._y + factory._height, factory.xTarget, factory._y + factory._height + 120, _root.tankSpeed, 2 ));
            }
        else if (type == "builder")
            {
            builders.addUnit ( new Builder(factory.xTarget, factory._y + factory._height, factory.xTarget, factory._y + factory._height + 120, _root.builderSpeed, 2 ));
            }

There are more tankTeams, there for it decides in what team the tank should be added. There’s only one buildTeam, that would be builders.

Here’s the method of the buildTeam class (builders.addUnit();


    public function addUnit (unit:Builder):Void
        {
        members.push (unit);
        }

The code for a new tank is working PERFECTLY. However, with the builders things get messed up. This shouldn’t happen as a builder is exactly the same, with the same parameters as an tank. Another strange thing is that the builder is working correctly. There is nothing wrong with it, I can control it when I create it the same way for my team. But when I trace (unit), it traces undefined!

Can anyone please tell me WHY a reference of an object would just… dissapear, lose it’s value.

It makes NO SENSE!

Any help greatly appreciated,
ArmoredSandwich aka ImWithNoob.