简体   繁体   中英

Communication issue between functions into JS and JSX files

I have made this function into a JS file...

function getColors(isPick, isForecolor)
{
    var chosenFunction = 'getColor(' + isPick + ', ' + isForecolor + ')';
    csInterface.evalScript(chosenFunction, function(result)
    {
        if(result !== 'undefined')
        {
            if (isForecolor == true){
                foregroundHexColor = result;
                // etc...
            }
            else
            {
                backgroundHexColor = result;
                //etc..
            };
        };
    });
};

which get a hexadecimal color value from this function from a JSX file.

function getColor(isPick, isForecolor)
{
    var color_PickerCase;
    var decimal_Color;
    var hexadecimal_Color;

    if (isForecolor == true)
    {
        color_PickerCase = app.foregroundColor.rgb.hexValue;
    }
    else
    {
        color_PickerCase = app.backgroundColor.rgb.hexValue;
    };

    if (isPick == true)
    {
        if (app.showColorPicker(isForecolor)){
            decimal_Color = color_PickerCase;
            hexadecimal_Color = decimal_Color.toString(16);
        }
        else
        {
            return;
        };
    }
    else
    {
        decimal_Color = color_PickerCase;
        hexadecimal_Color = decimal_Color.toString(16);
    };

    return hexadecimal_Color;    
};

In some way it works, but for some reason I have to do the same thing two times so to get the value?!! Any idea why is this happening?

Thank you for your time!!!

UPDATE : A correction, it works only at first click. Then needs to clicked two times so to get the value!!!

Well, here is the solution...

function getColor(isPick, isForecolor)
{
    var color_PickerCase;
    var decimal_Color;
    var hexadecimal_Color;

    if (isPick === true && app.showColorPicker(isForecolor) === false)
    {
            return;
    }

    if (isForecolor === true)
    {
        color_PickerCase = app.foregroundColor.rgb.hexValue;
    }
    else
    {
        color_PickerCase = app.backgroundColor.rgb.hexValue;
    }

    decimal_Color = color_PickerCase;
    hexadecimal_Color = decimal_Color.toString(16);
    return hexadecimal_Color;    
};

As joojaa from graphicdesign said, I was asking for the color before picking it and I was getting the color form the last time!!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM