Skip to content

Instantly share code, notes, and snippets.

@jacomyal
Created June 14, 2011 19:41
Show Gist options
  • Save jacomyal/1025690 to your computer and use it in GitHub Desktop.
Save jacomyal/1025690 to your computer and use it in GitHub Desktop.
How to open an URL when clicking a node with SiGMa-core:
// To react a node clicking, you have to listen to the
// event InteractionControler.CLICK_NODES:
InteractionControler.addEventListener(InteractionControler.CLICK_NODES,onClickNodes);
function onClickNodes(e:ContentEvent):void{
// e is a ContentEvent, with an array containing the
// IDs of each node under the mouse cursor during the
// click:
var clickedNodeIDs:Array = e.content;
// We suppose here that the most relevant node is the
// last one (the one "on the top") of the array:
var nodeID:String = clickedNodeIDs[clickedNodeIDs.length-1];
// Graph.nodesIndex gives you the index of a node in
// the nodes vector from its ID (Graph.nodes):
var node:Node = Graph.nodes[Graph.nodesIndex[nodeID]];
// We suppose here that the URL is contained in the attribute
// "url" of the nodes:
var url:String = node.attributes["url"];
var request:URLRequest = new URLRequest(url);
try {
navigateToURL(request, '_blank');
} catch (e:Error) {
trace("An error occurred!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment