Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

Allow nodes to fire events at super nodes

#146

Support the firing of events up the scene graph at render time, as shown below.

Basic Case

SceneJS has a two-pass event handling model: on the first traversal, "alpha/bravo/charlie" will fire "hello". Then on the second traversal, "alpha" will discover the event and report it. This gives "alpha" the opportunity to react to the previous traversal's events within its subgraph before the subgraph is re-rendered.

SceneJS.node({
        sid: "alpha",
        listeners: {
            "hello" : function(event) {
                alert("Node " + this.getSID() + " received event 'hello' from " + event.uri + " with param favColour: '" + event.params.favColour + "'"):
           }
        }
    },
    SceneJS.node({ sid: "bravo" },
        SceneJS.node({ 
                sid: "charlie",
                listeners: {
                     "rendering": function() {
                         this.fireEvent("hello", { favColour: "green" }); // no params
                     }
                }
            })));

Events across Instance-Symbol Links

Event management tracks the dynamic trail of node visits during traversal and guarantees that events bubble up that trail, no matter how many dynamic and recursive instancing links it traverses through. For example:


/* First symbol
*/
SceneJS.symbol({ sid: "bravo" },
    SceneJS.node({ 
            sid: "charlie",
            listeners: {
                 "rendering": function() {
                     this.fireEvent("hello", { favColour: "green" }); // no params
                 }
            }
        })),

/* Second symbol, instances the first symbol
 */
SceneJS.symbol({
        sid: "bravo2"        
    }, 
    SceneJS.instance({
            uri: "bravo"
        }));
   
/*  Event handler, instances the second symbol
 */     
SceneJS.node({
        sid: "alpha",
        listeners: {
            "hello" : function(event) {
                alert("Node " + this.getSID() + " received event 'hello' from " + event.uri + " with param favColour: '" + event.params.favColour + "'"):
           }
        }
    },
    SceneJS.instance({
        uri: "bravo2"
    }
);

Reported by lindsay.kay (at xeolabs) · August 11th, 2010 @ 03:25 AM

State: resolved
Milestone: V0.7.7

Activity

No comments yet.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.