Button/Color and Script AE
Hey Everyone,
Hoping someone can help.
So I have a button, the button is coloured based on an array. When that button is pushed my layer has a fill added with that colour.
Now, if I launch a script UI from the CEP panel. My script UI has the button etc.
But I want my buttons to be in the CEP panel instead of loads of Script UI's being opened. So I've built it into the panel instead.
Sometimes it works, sometimes it breaks and tells me I have errors, even though I've not changed anything. So, can someone suggest a better way to write the following so it doesn't bug all the time.
I've included the other bits, just incase you thought I might be missing them or there is something you might spot. Because I'm not fluent in javascript, I've had to do some bits in JQuery. This was all working yesterday, but now it's flagging back errors.
var csInterface = new CSInterface;
function hexToColor(theHex){
theHex = parseInt(theHex,16);
var r = theHex >> 16;
var g = (theHex & 0x00ff00) >> 8;
var b = theHex & 0xff;
return [r/255,g/255,b/255,1];
}
var primary = ["003469","00528A","808285","A8AAAC"];
function mainColor () {
for (var i = 0; i < primary.length; i++) {
document.getElementById("main").innerHTML += "<button data-name='"+ primary + "' style='background-color:#"+ primary + ";width: 55px; height: 32px; margin: 2px 4px;'' onclick='myFunction()'></button>";
}
$('#main button').click(function(){
csInterface.evalScript(
'var newColor = hexToColor("'+$(this).attr('data-name')+'");\
var curItem = app.project.activeItem;\
var selectedLayers = curItem.selectedLayers;\
for (var j = 0; j < selectedLayers.length; j++) {\
try {\
curRem = selectedLayers
selectedLayers
}catch (err){\
selectedLayers
}\
}'
);
})
}
mainColor();
