richardlord/Ash — Issue #3: NodeList's nodeAdded dispatched again and again.
Author: tamt
Created: 2012-03-05 02:55:17+00:00
State: open

The NodeList’s nodeAdded signal was dispatched when adding an component to Node’s entity

//in "addToGame"...
objs = game.getNodeList(ObjectNode);
objs.nodeAdded(addObjectToWorld);

//in "addObjectToWorld"...
function addObjectToWorld(node:ObjectNode)
{
var skin:SkinComponent = new SkinComponent();

//just add a SkinComponent to the Entity, but this will make the "nodeAdded" signal dispatched and "addObjectToWorld" was called again. and again....
node.entity.add(skin);
}

In Family.as, found:

internal function addIfMatch( entity : Entity ) : void{
if( !entities[entity] ){
...
nodes.add( node );
entities[entity] = node;
...
}
}
the NodeList.add is executed before store node in entities, which means the nodeAdded is dispatched before store node in entities. and the condition "!entities[entity]" will always be true...

I moved the codeline "entities[entity] = node;" before "nodes.add(node);", looks work fine. but i don't know whether it's will break Richardlord's design.