Copy link to clipboard
Copied
Again another question on best methods/practices using JavaScript. In AppleScript I can do this (my filter again):
delete (every channel whose kind is not component channel)
In JavaScript would I be best served by checking the mode (know how many channels I should have) and remove the rest? Loop through all using if else on ChannelType.SELECTEDAREA etc. Also Im thinking all the channels will be at the end so is a reversed loop possible? What I have been tinkering with so far is this:
var docRef = app.activeDocument;
var docMode = docRef.mode;
var docChannels = docRef.channels;
var chanCount = docRef.channels.length;
if (chanCount > 3) {
alert(chanCount);
for ( var i = 0; i < chanCount; i++ ) {
if( docChannels.kind == ChannelType.MASKEDAREA ){
alert("MA channel");
// I will remove this
}
if( docChannels.kind == ChannelType.SELECTEDAREA ){
alert("SA channel");
// I will remove this
}
if( docChannels.kind == ChannelType.SPOTCOLOR ){
alert("SC channel");
// I will merge this
}
}
}
can I use something like this ( var i = chanCount; i = 0; i-- ) or have I overlooked something completely?
for ( var i = docChannels.length-1; i >= 0; i-- ) {
var channel = docChannels+;
//...
}
Copy link to clipboard
Copied
OK, I tried this and it looks like I can reverse loop with this:
var chanCount = 6
for ( var i = chanCount; i > 0; i-- ) {
alert(i);
}
But Im sure I need to fix using somethings.length so the zero based thing works Im I correct?
Copy link to clipboard
Copied
for ( var i = docChannels.length-1; i >= 0; i-- ) {
var channel = docChannels+;
//...
}
Copy link to clipboard
Copied
I had tried using "=" and using ">" not the ">=" operator…
Can I also take it that I can also change the "--" or "++" shorthands to say "+ 3" and jump?
Copy link to clipboard
Copied
Can I also take it that I can also change the "--" or "++"
i++;
is the same as
i += 1;
is the same as
i = i + 1;
shorthands to say "+ 3" and jump?
You've lost me here.
Copy link to clipboard
Copied
If by jump you mean step
i += 3
or
i = i + 3
would step 3
Copy link to clipboard
Copied
Yep thats what I meant but did not explain very clearly…
What I managed to work out was the last one in both yours & x's posts
var chanCount = 15
for ( var i = chanCount; i >= 0; i = i - 3 ) {
alert(i);
}
so cool