How to use the same Class name when duplicating a symbol on new scene?

Hi,

I have a symbol that takes data from json file and injects text data into all text boxes on screen with a given Class name.

All works fine until I duplicate the symbol in another scene.

The data now fails to load because of duplicate Class names on different scenes but isnt this the whole reason for Classes ?

Any advice guys? Thanks

yes, and it works :slight_smile: so something in your script / workflow does not handle things as you expect :slight_smile:
another question to ask the crystal ball :wink: sry

Cheers prob conflicting var names or something simple. Thanks @h_classen

say you’ve got a normal symbol on several scenes. this symbol contains a single rect with a class ‘test’.
onsymbolload you run
element.getElementsByClassName('test')[0].innerHTML = 'test'

across the document every of these symbols will contain ‘test’

1 Like

Thanks for the help @h_classen heres my working solution. Seems to be working as intended now but little more testing to be done.

var outputText = ‘’;

if (!localStorage.visited) { 
var xmlhttp = new XMLHttpRequest();
		var url = "${resourcesFolderName}/correctModalTEXT.json";
		
		xmlhttp.onreadystatechange = function() { 
		    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { 
		        var data = JSON.parse(xmlhttp.responseText);
		        
		        loadSceneText(data);
		        return false;
		    } 
		}; // close 3data

xmlhttp.open("GET", url, true);
xmlhttp.send();

function loadSceneText(data) { 

var CMText = element.getElementsByClassName('correctModalTEXT');

for (var i = 0; i <= data.pageContent.length; i++) {

 var text = data.pageContent[i]; 
 
	for (key in text) {
		if (text.hasOwnProperty(key)) {
			outputText += '<u>' +
		 	text[key] +
			'</u>';
			
			 CMText[i].innerHTML = text[key];
 
		} // hasOwnProperty check
	
	} // for each object
	
} //for each array element

} //close displayScene()
	} // close (if else)
	 else { }
//end

this#ll overwrite the innerHTML for every key as the CMText[i] will stay the same in this iteration ...

Yes thanks, the data in my user feedback symbol does not change from scene to scene so the function will load my json data as seen here view sample scene > allowing for multiple languages and easy editing ! It works so im happy :grin: cheers :beers: @h_classen

1 Like