SpotColor to GrayColor converter (javaScript)

This could be edited to change any spot color to grayscale, currently it is aimed at a color called "spot black". The reason this is better then just using "edit/edit colors/convert to grayscale" is that the tones stay the same value. I'm sure it could be improved, I'm just sharing it so if someone is having the issues I was having they might have an easier time fixing it. The script originated with CarlosCanto on this discussion http://forums.adobe.com/thread/1267562?tstart=0 and was discussed further in this discussion http://forums.adobe.com/message/5610447#5610447. Enjoy.
// script.name = grayscaleFromSpotBlack.jsx;
// script.description = changes art color from a Spot swatch named "spot black", to Grayscale tones;
// script.requirements = an opened document;
// script.parent = CarlosCanto // 08/08/13;
// script.elegant = false;
// reference http://forums.adobe.com/thread/1267562?tstart=0 && http://forums.adobe.com/message/5610447#5610447
// Note: color values get rounded to the nearest integer, to avoid values like black = 99.99999999999999
//              Hidden and/or Locked Objects will be ignored, as well as objects in Hidden and/or Locked Layers
#target Illustrator
var idoc = app.activeDocument;
var pi = idoc.pathItems;
var tf = idoc.textFrames;
var fcounter = 0;
var scounter = 0;
var gcounter = 0;
//apply grayscale to paths and gradient stops
for (j=0; j<pi.length; j++) {
    var ipath = pi[j];
    if (ipath.hidden==false && ipath.locked==false) {
        if (meetTheParents(ipath) == "isLayerFree"){
            if (isLayerFree(ipath.parent)){
                changePath(ipath);
            } else {
                if (isGroupFree(ipath)){
                    changePath(ipath);
// choose text and change
for (t=0; t<tf.length; t++) {
    var iTxtFrm = tf[t];
    if (iTxtFrm.locked==false && iTxtFrm.hidden==false) {
        if (meetTheParents(iTxtFrm) == "isLayerFree"){
            if (isLayerFree(iTxtFrm.parent)){
                changeText(iTxtFrm);
            } else {
                if (isGroupFree(iTxtFrm)){
                    changeText(iTxtFrm);
alert(fcounter + ' Fill(s), ' + scounter + ' stroke(s) & ' + gcounter + ' Gradient Stop(s) processed.');
function meetTheParents(PageItem){
    if (PageItem.parent.typename = "Layer"){
        return "isLayerFree";
    } else if (PageItem.parent.typename = "GroupItem"){
        return "isGroupFree";
function isGroupFree(groupItem){
    if (groupItem.parent.hidden==false && groupItem.parent.editable==true){
        if (groupItem.parent.typename == "Layer"){
            var greatgpa = groupItem.parent;
            isLayerFree(greatgpa);
        }else if (groupItem.parent.typename = "GroupItem"){
            var gpa = groupItem.parent;
            if (isGroupFree(gpa));
            return true
            } else {
            return false
function isLayerFree(layer){
    if (layer.locked == false && layer.visible == true){
        var gpa = layer.parent;
        isLayerFree(gpa);
        return true
        } else {
        return false
// actually changes text
function changeText(textFrame){
    var chars = textFrame.characters;
    for (c=0; c<chars.length; c++) {
        var ltr = chars[c];
        if (ltr.characterAttributes.fillColor.typename == "SpotColor"){
            if (ltr.characterAttributes.fillColor.spot.name == "spot black"){
                var fillk = Math.round(ltr.characterAttributes.fillColor.tint);
                SpotToGrey (ltr, true, false, fillk);
                fcounter++;
        if (ltr.characterAttributes.strokeColor.typename == "SpotColor"){
            if (ltr.characterAttributes.strokeColor.spot.name == "spot black") {
                var strokek = Math.round(ltr.characterAttributes.strokeColor.tint);
                SpotToGrey (ltr, false, true, strokek);
                scounter++;
//actually changes paths
function changePath(PathItem){
    var fillColor = PathItem.fillColor;
    if (fillColor.typename == "SpotColor") {
        if (fillColor.spot.name == "spot black") {
            var fillk = Math.round(fillColor.tint);
            SpotToGrey (PathItem, true, false, fillk);
            fcounter++;
    else if (fillColor.typename == "GradientColor") {
        var stops = PathItem.fillColor.gradient.gradientStops;
        for (s=0; s<stops.length; s++) {
            var iStop = stops[s];
            var stopColor = iStop.color;
            if (stopColor.typename == "SpotColor") {
                if (stopColor.spot.name == "spot black") {
                    var stopk = Math.round(stopColor.tint);
                    iStop.color = GrayColor;
                    iStop.color.gray = stopk;
                    gcounter++;
    var strokeColor = PathItem.strokeColor;
    if (strokeColor.typename == "SpotColor") {
        if (strokeColor.spot.name == "spot black") {
            var strokek = Math.round(strokeColor.tint);
            SpotToGrey (PathItem, false, true, strokek);
            scounter++;
    else if (strokeColor.typename == "GradientColor") {
        var stops = PathItem.strokeColor.gradient.gradientStops;
        for (s=0; s<stops.length; s++) {
            var iStop = stops[s];
            var stopColor = iStop.color;
            if (stopColor.typename == "SpotColor") {
                if (stopColor.spot.name == "spot black") {
                    var stopk = Math.round(stopColor.tint);
                    iStop.color = GrayColor;
                    iStop.color.gray = stopk;
                    gcounter++;
function SpotToGrey (path, fill, stroke, k) {
    if (fill) {
        path.fillColor = GrayColor;
        path.fillColor.gray = k;
    if (stroke) {
        path.strokeColor = GrayColor;
        path.strokeColor.gray = k;
A file that shows what this script does will be hosted here https://docs.google.com/file/d/0BzEoJSYDhH_WekNoYTFzVHVaOXM/edit?usp=sharing until I forget why it's saved there and delete it.

Nice work on all the progress/additions you have made through all these threads, some good stuff, thanks for sharing and thanks as always to CarlosCanto as well.

Similar Messages

  • Convert Javascript to Applescript

    Hi,
    I need to convert javascript to Apple script. Please help!!!
    try {
    app.activeDocument.layers.getByName( '.ARD' ).remove(); } catch (e) {};
    MOhan

    tell application "Adobe Illustrator"
              tell the current document
                        try
                                  delete (the first layer whose name is ".ARD")
                        end try
              end tell
    end tell
    It's always a help if you state the language choice in the question…
    Edit… a change of string filter
    tell a
    tell application "Adobe Illustrator"
              tell the current document
                        try
                                  delete (the first layer whose name ends with ".ARD")
                        end try
              end tell
    end tell

  • Acrobat Web Capture cannot convert javascript links...?

    In Matrix (Multiple Listing Service) Acrobat Adobe 10 Standard won't convert javascript links in newly created PDFs Documents from Matrix.   The Error message is : Acrobat Web Capture cannot convert javascript links and the link often does not work correctly when opened in the web browser...  
    Is there any javascript download or work around program that can fix this problem?
    Thanks

    Probably not. Pretty hard for Acrobat to handle all of the web JavaScript and possible function calls that could appear on a web page and be located in another directory.
    If this is important to you, you can use the bug report/feature request page at adobe.com..

  • Convert javascript array to java array

    Is there any way possible to convert javascript array to java array?

    if you will try to experiment a javascript array
    putting it to a hidden element, it will be converted
    to a string (comma delimited). You can get the value
    of that element as a string and use StringTokenizer
    class to put the values into a java arrayThanks, got it.

  • How to convert javascript alert message into an Inline message in Apex Page

    Hi All. Im new to Apex.
    Present Approach -
    I have a dynamic report region developed using API's like APEX_ITEM etc. I am using java scripts to validate these dynamic items and popup alert messages as shown below -
    function ValidateNotObservedCB(p_row_num)
    var v_row_num = p_row_num;
    var v_not_observed_cb_status = document.getElementById('f_notobserved_'+v_row_num).checked;
    var v_not_in_district_cb_status = document.getElementById('f_notindistrict_'+v_row_num).checked;
    var v_program_code = document.getElementById("f_program_code_"+v_row_num).value;
    if ( (v_program_code.length>0)&& ( document.getElementById('f_notobserved_'+v_row_num).checked==true ))
         bold alert("You have already entered a program code.") bold
         document.getElementById('f_notobserved_'+v_row_num).checked=false ;
         document.getElementById('f_notobserved_'+v_row_num).value='N';
    } else if ( (v_program_code.length==0)&& ( document.getElementById('f_notobserved_'+v_row_num).checked==true )) {
         document.getElementById('f_notobserved_'+v_row_num).value='Y';
         document.getElementById('f_notobserved_'+v_row_num).checked=true ;
    } else
         document.getElementById('f_notobserved_'+v_row_num).checked=false ;
         document.getElementById('f_notindistrict_'+v_row_num).checked=false;
         document.getElementById('f_notindistrict_'+v_row_num).value='N';
         document.getElementById('f_notobserved_'+v_row_num).value='N';
    Question/Issue - How can I convert these alert messages into Inline messages to show on the page, similar to what appears when we do Item Validations in APEX.
    Waiting for responses as this is an urgent requirement.
    Thanks in Advance,
    Madhu

    Hi,
    I did with jQuery small sample
    http://apex.oracle.com/pls/otn/f?p=40323:36
    Page HTML header is
    <script type="text/javascript">
    $(function(){
      var lImg = $('<img alt="" class="pb" style="float: right;" src="/i/delete.gif"/>');
      var lMesg = $('<div id="MESSAGE" style="border-top: 1px solid rgb(142, 170, 142); border-bottom: 1px solid rgb(142, 170, 142); padding: 5px; background: rgb(235, 241, 235) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; width: 450px;" class="t14notification"></div>');
      $('.pb').live('click',function(){
        $x_Remove("MESSAGE");
      $('#SUBMIT').click(function(){
        if($('#MESSAGE').length == 0){
          $('#t14Messages').children().append($(lMesg));
           $(lMesg).append($(lImg));
           $(lImg).after($('#P36_NOTIFICATION').val());
        }else{
           $('#MESSAGE').text('');
           $('#MESSAGE').append($(lImg));
           $(lImg).after($('#P36_NOTIFICATION').val());
    </script>I do not know does it help. Using this depend much on theme, defined class and IDs.
    Br, Jari

  • Easy way to convert javascript to a java applet?

    Hello all! I am relatively new to java and java programming and had a question about converting a JavaScript to a java applet or even a standalone application. I included the JavaScript code for a checkers game below and wanted to know what would be the easiest way to convert this code if at all possible?
    Thanks in advance,
    Bob
    <SCRIPT language=JavaScript>
    <!--
    version = 1.0;
    // -->
    </SCRIPT>
    <SCRIPT language=JavaScript1.1>
    <!--
    version = 1.1;
    // -->
    </SCRIPT>
    <SCRIPT language=JavaScript>
    <!--
    if (version==1.0)
    document.write("Your browser doesn't have JavaScript 1.1 capabilities. "
    + "This checkers game script only works on Netscape 3+ and MSIE 4+.");
    // -->
    </SCRIPT>
    <SCRIPT language=JavaScript1.1>
    <!--
    // Checkers Game
    // black.gif
    // gray.gif
    // you1.gif -- normal piece (player/red)
    // you2.gif -- highlighted piece
    // you1k.gif -- kinged normal piece
    // you2k.gif -- kinged highlighted piece
    // me1.gif -- normal piece (computer/black)
    // me2.gif -- highlighted piece
    // me1k.gif -- kinged normal piece
    // me2k.gif -- kinged highlighted piece
    function preload() {
    this.length = preload.arguments.length;
    for (var i = 0; i < this.length; i++) {
    this[i] = new Image();
    this.src = preload.arguments[i];
    var pics = new preload("black.gif","gray.gif",
    "you1.gif","you2.gif","you1k.gif","you2k.gif",
    "me1.gif","me2.gif","me1k.gif","me2k.gif");
    var black = -1; // computer is black
    var red = 1; // visitor is red
    var square_dim = 35;
    var piece_toggled = false;
    var my_turn = false;
    var double_jump = false;
    var comp_move = false;
    var game_is_over = false;
    var safe_from = safe_to = null;
    var toggler = null;
    var togglers = 0;
    function Board() {
    board = new Array();
    for (var i=0;i<8; i++) {
    board[i] = new Array();
    for (var j=0;j<8;j++)
    board[i][j] = Board.arguments[8*j+i];
    board[-2] = new Array(); // prevents errors
    board[-1] = new Array(); // prevents errors
    board[8] = new Array(); // prevents errors
    board[9] = new Array(); // prevents errors
    var board;
    Board(1,0,1,0,1,0,1,0,
    0,1,0,1,0,1,0,1,
    1,0,1,0,1,0,1,0,
    0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,
    0,-1,0,-1,0,-1,0,-1,
    -1,0,-1,0,-1,0,-1,0,
    0,-1,0,-1,0,-1,0,-1);
    function message(str) {
    if (!game_is_over)
    document.disp.message.value = str;
    function moveable_space(i,j) {
    // calculates whether it is a gray (moveable)
    // or black (non-moveable) space
    return (((i%2)+j)%2 == 0);
    function Coord(x,y) {
    this.x = x;
    this.y = y;
    function coord(x,y) {
    c = new Coord(x,y);
    return c;
    document.write("<table border=0 cellspacing=0 cellpadding=0 width="+(square_dim*8+8)
    +"<tr><td><img src='black.gif' width="+(square_dim*8+8)
    +" height=4><br></td></tr>");
    for(var j=0;j<8;j++) {
    document.write("<tr><td><img src='black.gif' width=4 height="+square_dim+">");
    for(var i=0;i<8;i++) {
    if (moveable_space(i,j))
    document.write("<a href='javascript:clicked("+i+","+j+")'>");
    document.write("<img src='");
    if (board[i][j]==1) document.write("you1.gif");
    else if (board[i][j]==-1) document.write("me1.gif");
    else if (moveable_space(i,j)) document.write("gray.gif");
    else document.write("black.gif");
    document.write("' width="+square_dim+" height="+square_dim
    +" name='space"+i+""+j+"' border=0>");
    if (moveable_space(i,j)) document.write("</a>");
    document.write("<img src='black.gif' width=4 height="+square_dim+"></td></tr>");
    document.write("<tr><td><img src='black.gif' width="+(square_dim*8+8)
    +" height=4><br></td></tr></table><br>"
    +"<form name='disp'><textarea name='message' wrap=virtual rows=2 cols=40></textarea><br><input "
    +"type=button value=\"Start the Game Over\" onClick=\"location.href+=''\"></form>");
    function clicked(i,j) {
    if (my_turn) {
    if (integ(board[i][j])==1) toggle(i,j);
    else if (piece_toggled) move(selected,coord(i,j));
    else message("First click one of your red pieces, then click where you want to move it");
    } else {
    message("It's not your turn yet. Hang on a sec!");
    function toggle(x,y) {
    if (my_turn) {
    if (piece_toggled)
    draw(selected.x,selected.y,"you1"+((board[selected.x][selected.y]==1.1)?"k":"")+".gif");
    if (piece_toggled && (selected.x == x) && (selected.y == y)) {
    piece_toggled = false;
    if (double_jump) { my_turn = double_jump = false; computer(); }
    } else {
    piece_toggled = true;
    draw(x,y,"you2"+((board[x][y]==1.1)?"k":"")+".gif");
    selected = coord(x,y);
    } else {
    if ((piece_toggled) && (integ(board[selected_c.x][selected_c.y])==-1))
    draw(selected_c.x,selected_c.y,"me1"+((board[selected_c.x][selected_c.y]==-1.1)?"k":"")+".gif");
    if (piece_toggled && (selected_c.x == x) && (selected_c.y == y)) {
    piece_toggled = false;
    } else {
    piece_toggled = true;
    draw(x,y,"me2"+((board[x][y]==-1.1)?"k":"")+".gif");
    selected_c = coord(x,y);
    function draw(x,y,name) {
    document.images["space"+x+""+y].src = name;
    function integ(num) {
    if (num != null)
    return Math.round(num);
    else
    return null;
    function abs(num) {
    return Math.abs(num);
    function sign(num) {
    if (num < 0) return -1;
    else return 1;
    function concatenate(arr1,arr2) {
    // function tacks the second array onto the end of the first and returns result
    for(var i=0;i<arr2.length;i++)
    arr1[arr1.length+i] = arr2[i];
    return arr1;
    function legal_move(from,to) {
    if ((to.x < 0) || (to.y < 0) || (to.x > 7) || (to.y > 7)) return false;
    piece = board[from.x][from.y];
    distance = coord(to.x-from.x,to.y-from.y);
    if ((distance.x == 0) || (distance.y == 0)) {
    message("You may only move diagonally.");
    return false;
    if (abs(distance.x) != abs(distance.y)) {
    message("Invalid move.");
    return false;
    if (abs(distance.x) > 2) {
    message("Invalid move.");
    return false;
    if ((abs(distance.x) == 1) && double_jump) {
    return false;
    if ((board[to.x][to.y] != 0) || (piece == 0)) {
    return false;
    if ((abs(distance.x) == 2)
    && (integ(piece) != -integ(board[from.x+sign(distance.x)][from.y+sign(distance.y)]))) {
    return false;
    if ((integ(piece) == piece) && (sign(piece) != sign(distance.y))) {
    return false;
    return true;
    function move(from,to) {
    my_turn = true;
    if (legal_move(from,to)) {
    piece = board[from.x][from.y];
    distance = coord(to.x-from.x,to.y-from.y);
    if ((abs(distance.x) == 1) && (board[to.x][to.y] == 0)) {
    swap(from,to);
    } else if ((abs(distance.x) == 2)
    && (integ(piece) != integ(board[from.x+sign(distance.x)][from.y+sign(distance.y)]))) {
    double_jump = false;
    swap(from,to);
    remove(from.x+sign(distance.x),from.y+sign(distance.y));
    if ((legal_move(to,coord(to.x+2,to.y+2)))
    || (legal_move(to,coord(to.x+2,to.y-2)))
    || (legal_move(to,coord(to.x-2,to.y-2)))
    || (legal_move(to,coord(to.x-2,to.y+2)))) {
    double_jump = true;
    message("You may complete the double jump or click on your piece to stay still.");
    if ((board[to.x][to.y] == 1) && (to.y == 7)) king_me(to.x,to.y);
    selected = to;
    if (game_over() && !double_jump) {
    setTimeout("toggle("+to.x+","+to.y+");my_turn = double_jump = false;computer();",1000);
    return true;
    function king_me(x,y) {
    if (board[x][y] == 1) {
    board[x][y] = 1.1; // king you
    draw(x,y,"you2k.gif");
    } else if (board[x][y] == -1) {
    board[x][y] = -1.1; // king me
    draw(x,y,"me2k.gif");
    function swap(from,to) {
    if (my_turn || comp_move) {
    dummy_src = document.images["space"+to.x+""+to.y].src;
    document.images["space"+to.x+""+to.y].src = document.images["space"+from.x+""+from.y].src;
    document.images["space"+from.x+""+from.y].src = dummy_src;
    dummy_num = board[from.x][from.y];
    board[from.x][from.y] = board[to.x][to.y];
    board[to.x][to.y] = dummy_num;
    function remove(x,y) {
    if (my_turn || comp_move)
    draw(x,y,"gray.gif");
    board[x][y] = 0;
    function Result(val) {
    this.high = val;
    this.dir = new Array();
    function move_comp(from,to) {
    toggle(from.x,from.y);
    comp_move = true;
    swap(from,to);
    if (abs(from.x-to.x) == 2) {
    remove(from.x+sign(to.x-from.x),from.y+sign(to.y-from.y));
    if ((board[to.x][to.y] == -1) && (to.y == 0)) king_me(to.x,to.y);
    setTimeout("selected_c = coord("+to.x+","+to.y+");piece_toggled = true;",900);
    setTimeout("bak=my_turn;my_turn=false;toggle("+to.x+","+to.y+");my_turn=bak;",1000);
    if (game_over()) {
    setTimeout("comp_move = false;my_turn = true;togglers=0;",600);
    message("Ok. It's your turn. You may make your move.");
    return true;
    function game_over() { // make sure game is not over (return false if game is over)
    comp = you = false;
    for(var i=0;i<8;i++) {
    for(var j=0;j<8;j++) {
    if(integ(board[i][j]) == -1) comp = true;
    if(integ(board[i][j]) == 1) you = true;
    if (!comp) message("You beat me!");
    if (!you) message("Gotcha! Game over.");
    game_is_over = (!comp || !you)
    return (!game_is_over);
    // the higher the jump_priority, the more often the computer will take the jump over the safe move
    var jump_priority = 10;
    function computer() {
    // step one - prevent any jumps
    for(var j=0;j<8;j++) {
    for(var i=0;i<8;i++) {
    if (integ(board[i][j]) == 1) {
    if ((legal_move(coord(i,j),coord(i+2,j+2))) && (prevent(coord(i+2,j+2),coord(i+1,j+1)))) {
    return true;
    } if ((legal_move(coord(i,j),coord(i-2,j+2))) && (prevent(coord(i-2,j+2),coord(i-1,j+1)))) {
    return true;
    } if (board[i][j] == 1.1) {
    if ((legal_move(coord(i,j),coord(i-2,j-2))) && (prevent(coord(i-2,j-2),coord(i-1,j-1)))) {
    return true;
    } if ((legal_move(coord(i,j),coord(i+2,j-2))) && (prevent(coord(i+2,j-2),coord(i+1,j-1)))) {
    return true;
    // step two - if step one not taken, look for jumps
    for(var j=7;j>=0;j--) {
    for(var i=0;i<8;i++) {
    if (jump(i,j))
    return true;
    safe_from = null;
    // step three - if step two not taken, look for safe single space moves
    for(var j=0;j<8;j++) {
    for(var i=0;i<8;i++) {
    if (single(i,j))
    return true;
    // if no safe moves, just take whatever you can get
    if (safe_from != null) {
    move_comp(safe_from,safe_to);
    } else {
    message("You beat me!!");
    game_is_over = true;
    safe_from = safe_to = null;
    return false;
    function jump(i,j) {
    if (board[i][j] == -1.1) { 
    if (legal_move(coord(i,j),coord(i+2,j+2))) {
    move_comp(coord(i,j),coord(i+2,j+2));
    setTimeout("jump("+(i+2)+","+(j+2)+");",500);
    return true;
    } if (legal_move(coord(i,j),coord(i-2,j+2))) {
    move_comp(coord(i,j),coord(i-2,j+2));
    setTimeout("jump("+(i-2)+","+(j+2)+");",500);
    return true;
    } if (integ(board[i][j]) == -1) {
    if (legal_move(coord(i,j),coord(i-2,j-2))) {
    move_comp(coord(i,j),coord(i-2,j-2));
    setTimeout("jump("+(i-2)+","+(j-2)+");",500);
    return true;
    } if (legal_move(coord(i,j),coord(i+2,j-2))) {
    move_comp(coord(i,j),coord(i+2,j-2));
    setTimeout("jump("+(i+2)+","+(j-2)+");",500);
    return true;
    return false;
    function single(i,j) {
    if (board[i][j] == -1.1) {
    if (legal_move(coord(i,j),coord(i+1,j+1))) {
    safe_from = coord(i,j);
    safe_to = coord(i+1,j+1);
    if (wise(coord(i,j),coord(i+1,j+1))) {
    move_comp(coord(i,j),coord(i+1,j+1));
    return true;
    } if (legal_move(coord(i,j),coord(i-1,j+1))) {
    safe_from = coord(i,j);
    safe_to = coord(i-1,j+1);
    if (wise(coord(i,j),coord(i-1,j+1))) {
    move_comp(coord(i,j),coord(i-1,j+1));
    return true;
    } if (integ(board[i][j]) == -1) {
    if (legal_move(coord(i,j),coord(i+1,j-1))) {
    safe_from = coord(i,j);
    safe_to = coord(i+1,j-1);
    if (wise(coord(i,j),coord(i+1,j-1))) {
    move_comp(coord(i,j),coord(i+1,j-1));
    return true;
    } if (legal_move(coord(i,j),coord(i-1,j-1))) {
    safe_from = coord(i,j);
    safe_to = coord(i-1,j-1);
    if (wise(coord(i,j),coord(i-1,j-1))) {
    move_comp(coord(i,j),coord(i-1,j-1));
    return true;
    return false;
    function possibilities(x,y) {
    if (!jump(x,y))
    if (!single(x,y))
    return true;
    else
    return false;
    else
    return false;
    function prevent(end,s) {
    i = end.x;
    j = end.y;
    if (!possibilities(s.x,s.y))
    return true;
    else if ((integ(board[i-1][j+1])==-1) && (legal_move(coord(i-1,j+1),coord(i,j)))) {
    return move_comp(coord(i-1,j+1),coord(i,j));
    } else if ((integ(board[i+1][j+1])==-1) && (legal_move(coord(i+1,j+1),coord(i,j)))) {
    return move_comp(coord(i+1,j+1),coord(i,j));
    } else if ((board[i-1][j-1]==-1.1) && (legal_move(coord(i-1,j-1),coord(i,j)))) {
    return move_comp(coord(i-1,j-1),coord(i,j));
    } else if ((board[i+1][j-1]==-1.1) && (legal_move(coord(i+1,j-1),coord(i,j)))) {
    return move_comp(coord(i+1,j-1),coord(i,j));
    } else {
    return false;
    function wise(from,to) {
    i = to.x;
    j = to.y;
    n = (j>0);
    s = (j<7);
    e = (i<7);
    w = (i>0);
    if (n&&e) ne = board[i+1][j-1]; else ne = null;
    if (n&&w) nw = board[i-1][j-1]; else nw = null;
    if (s&&e) se = board[i+1][j+1]; else se = null;
    if (s&&w) sw = board[i-1][j+1]; else sw = null;
    eval(((j-from.y != 1)?"s":"n")+((i-from.x != 1)?"e":"w")+"=0;");
    if ((sw==0) && (integ(ne)==1)) return false;
    if ((se==0) && (integ(nw)==1)) return false;
    if ((nw==0) && (se==1.1)) return false;
    if ((ne==0) && (sw==1.1)) return false;
    return true;
    message("You may begin! Select a piece to move.");
    my_turn = true;
    // -->
    </SCRIPT>

    Well, you can get a free tutorial to Java at http://www.mindview.net/. It's the "Thinking In Java" book. You can download the whole book from that site, it's about a thousand pages. If you read that whole book, you'll know exactly where to start and probably how to finish it too.
    As a gimmie, think about it -- you'll have to remove all of the browser-detect code, since browser-detection is only done to determine which version of JavaScript is supported by the browser.

  • Help! Converting JavaScript to Java

    I know I am going to get laughed at for this, but as you can probably tell my knowledge of Java is poor at best.
    Years ago, I wrote the following code in JavaScript:
    function overImg(imageName)
        if (version == "java")
            imageOn = eval(imageName + "roll.src");
            document [imageName].src = imageOn;
    }Question is, how can I recreate something similar in Java?
    The key part is that the code allows me to use a reference to an object rather than the object itself. How can I do that in Java?
    If this question seems stupid then feel free to tell me so. I freely admit my knowledge of Java is not good.
    Thank you in advance,
    G

    If I had a search method, how can I pass the book object to the method >if I don't know what the object will be called when I compile?Something like this...
    Library.java
    private List bookList;
    public boolean search(Book b){
        String isbn = b.getISBN();
        return bookList.contains(isbn);
    public void addBook(Book b){
        bookList.add(b.getISBN());
    Library.java
    public String getISBN(){
       //return an isbn for this book

  • Converting JavaScript "Variables"/Functions into Designer 7

    Hi,
    I'm upgrading our Forms which were created in Adobe 6 to Adobe 7 with Adobe Designer 7. One of the biggest problems that I'm encountering is the function library we developed in-house, which now shows under 'variables' at the Form level. The whole library was written in JavaScript.
    Listed below is a sample function:
    ----- F.#variables[0].DL_resetDefaultColor::DL_resetDefaultColor - (JavaScript, client) ------------
    # This function resets all the field elements to its default color ***************************************************************/ function DL_resetDefaultColor()
    //Get the array of all the form field elements names
    rArray = DL_getFormElements(); //Calling another function
    for (var i=0; i < rArray.length; i++) { DL_setDefaultColor(rArray[i]); } }
    Most of these functions are called from Button::mouseUp events, however when the button is clicked the Debugger gives the following error:
    TypeError: DL_resetDefaultColor is not a function
    6:XFA:F[0].P1[0].button_name[0]:mouseUp
    Please help in explaining how I may do this with Designer.
    Thank you,
    Ali

    Do you have this fixed yet?

  • Convert Javascript: switch(xfa.event.newText) to Formcalc Syntax

    I was wondering if someone could provide me with the syntax for formcalc for the following javascript. This is used to hide or make visible 2 fields based on a value in a drop down list:
    switch(xfa.event.newText) {
        case 'A - Approved':
            form1.Page1.2nd_Title.presence = "visible";
            form1.Page1.2nd_Signature.presence = "visible";
            break;
       default:
            form1.Page1.2nd_Title.presence = "hidden";
            form1.Page1.2nd_Signature.presence = "hidden";
            break;
    Thanks,
    Mallard27

    Sorry, no simple switch-like statement in FormCalc, although there are convoluted ways to simulate it.  For your example the easiest is if/then/else:
    if (xfa.event.newText == "A - Approved") then
         form1.Page1.TextField1.presence = "visible"
         form1.Page1.TextField2.presence = "visible"
    else
         form1.Page1.TextField1.presence = "hidden"
         form1.Page1.TextField2.presence = "hidden"
    endif
    Also, not sure if you can have object names that start with a number, like "2nd_Title".

  • Just had Javascript update done and now Firefox won't open,,,keeps coming up with XML Parsing error not well formed. how can I get rid of this?

    also awindow pops up NS error XPC Bad convert JS cannot convert JAVASCRIPT argument arg 4 (NSL window watcher open window)
    == This happened ==
    Every time Firefox opened
    == just today ==
    == User Agent ==
    Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; (R1 1.5))

    There's a lot there, so I'll start with the parts I can answer quickly.
    The "ACL found but not expected..." messages can be safely ignored, so says this article
    http://docs.info.apple.com/article.html?artnum=306925
    (look below all the "SUID" examples)
    I had changed my Desktop image earlier but when the "Installing 1 item" window came up it changed back to the back ground that you first see on your desktop after installation.
    Leopard installs updates a bit differently. If it's simply an application that does not change system files, it installs them like before, without having to restart. If the update is to the system, then you must immediately "restart," It then goes to that stars and purple screen to perform the installation. Before, it would do the installation while you still had control of the Mac and would prompt you to restart when it finished the installation. This change probably make things more secure and reliable, because you aren't allowed to do other things on the Mac while system updates are being installed.
    Please post back with the remaining point of concern.

  • Javascript error when open firefox

    When I try to open Firefox, I get a long pause and then this error message: [Exception... "Could not convert JavaScript argument arg 0 [nsISupports.QueryInterface]" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: chrome://searchshield/content/overlay.js :: InitSDK :: line 473" data: no]
    Firefox then opens. This does not occur with Internet Explorer. This just started happening today. What is this, and how do I fix this? I am just a regular user, not a tech person. Thanks.

    This issue is caused by the an AVG extension probably AVG Security toolbar.
    *https://support.mozilla.com/kb/Troubleshooting+extensions+and+themes
    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.com/kb/Safe+Mode

  • Capturing javascript tab controls?

    I'm working on archiving a website using Acrobat Pro 9.x. There are many pages in which the content is in tabs switched by javascript (toggling the CSS divs to hide or display). However, "Web Capture cannot convert javascript links ... ", so content not on the default tab is lost. Are there any workarounds for this? Even opening all the tabs simultaneously, as if the user has turned off javascript, would be fine.

    change "Tab Control" to indicator
    Attachments:
    tab control labview8.2.1.vi ‏11 KB

  • Run javascript in adobe live cycle work bench

    Hi All,
    Is there anyway we can execute the javascript in workbench?
    or is there any method to convert javascript to adobe script(execute script activity)?
    Actually i have written javascript in live cycle designer while pdf designing. now i want the same javascript at server end.
    Kindly someone help me to get this functionality.
    Regards
    Abhishek

    Hi Jasmin,
    Thanks for your quick reply.
    I have a javascript which generate sha1hash output for input string.
    I am getting an error while executing it in workbench.
    If i want to use same algorithm in execute script how can i able to use it.
    How should i convert this code in java?
    Please find the javascript below for sha1hash algorithm
    function sha1Hash(msg)
        // constants [§4.2.1]
        var K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6];
        // PREPROCESSING
        msg += String.fromCharCode(0x80); // add trailing '1' bit (+ 0's padding) to string [§5.1.1]
        // convert string msg into 512-bit/16-integer blocks arrays of ints [§5.2.1]
        var l = msg.length/4 + 2;  // length (in 32-bit integers) of msg + ‘1’ + appended length
        var N = Math.ceil(l/16);   // number of 16-integer-blocks required to hold 'l' ints
        var M = new Array(N);
        for (var i=0; i<N; i++) {
            M[i] = new Array(16);
            for (var j=0; j<16; j++) {  // encode 4 chars per integer, big-endian encoding
                M[i][j] = (msg.charCodeAt(i*64+j*4)<<24) | (msg.charCodeAt(i*64+j*4+1)<<16) |
                          (msg.charCodeAt(i*64+j*4+2)<<8) | (msg.charCodeAt(i*64+j*4+3));
        // add length (in bits) into final pair of 32-bit integers (big-endian) [5.1.1]
        // note: most significant word would be (len-1)*8 >>> 32, but since JS converts
        // bitwise-op args to 32 bits, we need to simulate this by arithmetic operators
        M[N-1][14] = ((msg.length-1)*8) / Math.pow(2, 32); M[N-1][14] = Math.floor(M[N-1][14])
        M[N-1][15] = ((msg.length-1)*8) & 0xffffffff;
        // set initial hash value [§5.3.1]
        var H0 = 0x67452301;
        var H1 = 0xefcdab89;
        var H2 = 0x98badcfe;
        var H3 = 0x10325476;
        var H4 = 0xc3d2e1f0;
        // HASH COMPUTATION [§6.1.2]
        var W = new Array(80); var a, b, c, d, e;
        for (var i=0; i<N; i++) {
            // 1 - prepare message schedule 'W'
            for (var t=0;  t<16; t++) W[t] = M[i][t];
            for (var t=16; t<80; t++) W[t] = ROTL(W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16], 1);
            // 2 - initialise five working variables a, b, c, d, e with previous hash value
            a = H0; b = H1; c = H2; d = H3; e = H4;
            // 3 - main loop
            for (var t=0; t<80; t++) {
                var s = Math.floor(t/20); // seq for blocks of 'f' functions and 'K' constants
                var T = (ROTL(a,5) + f(s,b,c,d) + e + K[s] + W[t]) & 0xffffffff;
                e = d;
                d = c;
                c = ROTL(b, 30);
                b = a;
                a = T;
            // 4 - compute the new intermediate hash value
            H0 = (H0+a) & 0xffffffff;  // note 'addition modulo 2^32'
            H1 = (H1+b) & 0xffffffff;
            H2 = (H2+c) & 0xffffffff;
            H3 = (H3+d) & 0xffffffff;
            H4 = (H4+e) & 0xffffffff;
        return H0.toHexStr() + H1.toHexStr() + H2.toHexStr() + H3.toHexStr() + H4.toHexStr();
    // function 'f' [§4.1.1]
    function f(s, x, y, z)
        switch (s) {
        case 0: return (x & y) ^ (~x & z);           // Ch()
        case 1: return x ^ y ^ z;                    // Parity()
        case 2: return (x & y) ^ (x & z) ^ (y & z);  // Maj()
        case 3: return x ^ y ^ z;                    // Parity()
    // rotate left (circular left shift) value x by n positions [§3.2.5]
    function ROTL(x, n)
        return (x<<n) | (x>>>(32-n));
    // extend Number class with a tailored hex-string method
    //   (note toString(16) is implementation-dependant, and
    //   in IE returns signed numbers when used on full words)
    Number.prototype.toHexStr = function()
        var s="", v;
        for (var i=7; i>=0; i--) { v = (this>>>(i*4)) & 0xf; s += v.toString(16); }
        return s;
    Please reply for this
    Thanks in advance.

  • Glassfish 2.1 Admin Console Javascript Error when selecting cluster targets

    I recently updated to Firefox 4 and when using the GlassFish 2.1 Admin Console and you have to manage the cluster targets for specific resources there is a javascript error which prevents you from selecting target cluster options. Basically you select what you want, but then it removes it immediately after.
    Using FireBug I can see the error below:
    uncaught exception: [Exception... "Could not convert JavaScript argument - 0 was passed, expected object. Did you mean null? arg 1 [nsIDOMHTMLSelectElement.add]" nsresult: "0x80570035 (NS_ERROR_XPC_BAD_CONVERT_JS_ZERO_ISNOT_NULL)" location: "JS frame :: http://localhost:4848/theme/META-INF/dojo/dojo.js :: <TOP_LEVEL> :: line 645" data: no]
    Line 0
    This functionality works fine in other browsers.
    Thanks.

    Hi there,
    Can you check the JDK version and see the compatible with your weblogic installation ?
    You can refer the certification matrix from Oracle to check the compatible version of JDK. Here you go - Oracle Fusion Middleware 12c (12.1.3.0.0) Certification Matrix.
    Most probably, this issue will occur when JDK is not compatible with weblogic installation..
    Lakshman

  • JavaScript  to Plugin

    How to convert Javascript as plugin for "Adobe illustrator CS"?
    Regards,
    Maria

    There are several sample plug-ins provided on the SDK, download from here - http://www.adobe.com/devnet/illustrator/sdk/
    Read the getting started guide to find your feet with developing C++ plug-ins for Illustrator and there is also a tutorial in the programmers guide for creating your first plug-in.

Maybe you are looking for

  • Why doesn't Adobe Color show CMYK colors?

    Adobe Kuler used to show RGB, CMYK, Hex and other values for every color. Adobe Color is showing only RGB and HEX. How do I get the corresponding CMYK values?

  • Who has had a PCI-DIO-32HS card fail, ever?

    I've looked through the forum somewhat and I've found little concerning the card itself failing.  For instance, I found something about the card failing due to driving it with a TTL high before it was powered, but that was about it as far as actual d

  • Possible to export XMP files only?

    I want to be able to export the metadata (captions, keywords and ratings) as XMP sidecars alongside my referenced RAW files. Currently the only way I can see to do this is to export the RAWs with an XMP file - i.e. I have to duplicate all my RAW file

  • Multilingual XML Approach

    Hi, I need to discuss one thing regarding multilingual implementation for an application. The requirement is given below. 1. only master data(user entry) of the application will support multilingual. 2. Application will support 'n' languages becuase

  • HT4437 ATV icon gone

    My icon on my computer  iTunes has disappeared apparently stppping AirPlay on my iPad. Now what..how to reset?