Adding JSON properties to a component via script?
-
Hello!
I'm stuck on what seems like a silly issue and I swear I've done it before.
I am adding a bunch of sliders to a panel in a for loop using
Content.addKnob
.
I want each of those knobs to have a custom JSON tag called "idNumber" or something.
Is there any way to add that "idNumber" JSON property and set it equal to the iterator of the for loop in script? I don't want to manually edit the JSON after the components are created.THANKS!
-
@ericchesek you can't add custom properties to a component, either through scripting or by manual editing.
-
@ericchesek What is it you are trying to achieve? When you are creating the sliders in a loop, are you appending the index number to each in the name?
Here are some examples of indexing for the ID:// a loop to create sliders inline function createSliders(stringName, numOfSliders) { local sliders = []; for (i = 0; i < numOfSliders; i++) { // this appends the index to the slider name: "stringName + i" local slider = Content.addKnob(stringName + i, 50 + i * 125, 50); // this stores the component object inside an array sliders[i] = slider; slider.set("style", "vertical"); } return sliders; } // call the function to create the sliders const mySliders = createSliders("MySlider", 4); // a separate array for the names ("Id") const mySlidersIdArray = mySliders.map(function(element){return element.getId();}); Console.print("mySlidersIdArray: " + trace(mySlidersIdArray));
So there are multiple ways to use an index as ID to associate with a component.
-
@VirtualVirgin Little unrelated tip of the day:
mySliders.map(function(element){return element.getId();});
can also be written as
mySliders.map(element => element.getId());
Arrow function expressions - JavaScript | MDN
An arrow function expression is a compact alternative to a traditional function expression, with some semantic differences and deliberate limitations in usage:
MDN Web Docs (developer.mozilla.org)