-
Sequential function execution for sourceText property
Hi, all.
I’ve been poking at this one for a while now and would like some help. I’m trying to combine two fairly complicated expressions to connect the sourceText property of a text layer to define and link to a dropdown menu in a control layer for font selection and to a slider on the same layer to allow a limited amount of characters per line (the latter of which I found on here, from Dan Ebberts). I’ve tried a few methods, but here’s where I’m at now:
font01 = "ProximaNova-Black"; font02 = "ProximaNovaCond-Black"; font03 = "ProximaNovaExCn-Black"; font04 = "ProximaNovaExWd-Black"; font05 = "ProximaNovaWide-Black"; font06 = "ProximaSera-Black"; font07 = "ProximaSoft-Black"; font08 = "ProximaSoftCond-Black"; font09 = "ProximaSoftExCn-Black";
dropMenu = comp("Master").layer("Control").effect("Dropdown Menu Control")("Menu").value-1; const fontArray = [font01, font02, font03, font04, font05, font06, font07, font08, font09]; const iterator = fontArray[dropMenu];txt = text.sourceText; n = comp("Master").layer("Control").effect("Text Width")("Slider"); outStr = ""; newLine = ""; splt = txt.split(" "); function txtp() { for (i = 0; i < splt.length; i++) { if ((newLine + " " + splt[i]).length > n) { if (outStr != "") outStr += "\r"; outStr += newLine; newLine = splt[i]; }else{ if (newLine != "") newLine += " "; newLine += splt[i]; } } if (newLine != "") { if (outStr != "") outStr += "\r"; outStr += newLine; } outStr; }text.sourceText.style .setFont(iterator) .setText(txtp)The font selection is working great, but I’m stumbling in two places here:
- First, for some reason the .setText(txtp) is filling the whole function into the source text, including the word “function” at the beginning all the way through the last }. It’s not executing txtp(), just changing the source text to “function textp() {” etc.
- Second, I’m aware part of the problem is that the txtp() function doesn’t return a value compatible with the .setText operator, but I’m not sure how to fix this. If I could get it to somehow return the modified text, that would be great.