Extend Tumult Hype with JavaScript: hypeDocument.extensions

hypeDocument.getSymbolInstance

This function is needed if you assign click handler or use Javascript inside a symbol and want to run for example timelines of the symbol. This code is from @stephen and put into extension form by @MaxZieb.

/**
 * hypeDocument.getSymbolInstance 1.0 (by Stephen)
 * @param {HTMLDivElement} element The starting point for the search
 * @return {symbolInstance} Is either the symbolInstance or null
 */
hypeDocument.getSymbolInstance = function(element){
	var symbolInstance = null;
	var parentSymbolElement = element.parentNode;
	while (symbolInstance == null && parentSymbolElement != null) {
		symbolInstance = this.getSymbolInstanceById(parentSymbolElement.id);
		parentSymbolElement = parentSymbolElement.parentNode;
	} 
	return symbolInstance;
}

Update: Here is an upgrade version (in my opinion). It also works if the current element is already the symbol you are searching for.

/**
 * hypeDocument.getSymbolInstance 1.1 (by Stephen, modified by Max Ziebell)
 * @param {HTMLDivElement} element The starting point for the search
 * @return {symbolInstance} Is either the symbolInstance or null
 */
hypeDocument.getSymbolInstance = function(element){
	var symbolInstance = null;
	while (symbolInstance == null && element != null) {
		symbolInstance = hypeDocument.getSymbolInstanceById(element.id);
		element = element.parentNode;
	} 
	return symbolInstance;
}

Usage:

symbolInstance = hypeDocument.getSymbolInstance(element);
1 Like