Highlighted

Checkbox Value

Community Beginner ,
May 17, 2017

Copy link to clipboard

Copied

Hello ,i am trying to ,with one button and a checkbox to switch between two functions.

But when i check the value of this checkbox ,at the first use,it works ,but then, when i change it,

it's always the value i use at the begining .

So i dont know how to verify after each click the new value of my checkbox ??

Here is my code ,if somebody has an idea..

Thank you everyone

function FILL(obj)

//===============================================

    //================= UI============================

    //===============================================

   

  {

       

    function addHGroup(conteneur){

  var groupe = conteneur.add("group");

  groupe.alignChildren = ["fill","fill"];

  groupe.orientation = "row";

  groupe.spacing = 1;

  groupe.margins = 0;

  return groupe;

    }

    function addVGroup(conteneur){

        var groupe = conteneur.add("group");

        groupe.alignChildren = ["fill","fill"];

        groupe.orientation = "column";

        groupe.spacing = 1;

        groupe.margins = 0;

        return groupe;

    }

            

    var fenetre = obj instanceof Panel ? obj : new Window("window","BS_TOOLS",undefined,{resizeable:true});

    fenetre.alignChildren = ["fill", "top"];

    fenetre.spacing  = 2;

    fenetre.margins = 2;

   

   

    var fillGroup01 = addHGroup(fenetre);

    fillGroup01.alignment = ["fill","top"];

    var FillButton01 = fillGroup01.add("button",undefined,"FILL"); 

 

   

    var fillGroup02 = addHGroup(fenetre);

    fillGroup02.alignChildren = ["fill","center"];

    var CheckButton = fillGroup02.add("checkbox",undefined,"Other Color?");

    CheckButton.size = [100,25];

  

   

   

//CLICK_______________________________________________________________________________

FillButton01.onClick=function Choix() {if (CheckButton.value==false) {FillButton01.onClick=MyFunction01}else{FillButton01.onClick=MyFunction02}};

//FUNCTIONS ____________________________________________________________________

  

   

   

    function MyFunction01()

{

// create an undo group

app.beginUndoGroup("AddEffect");

var curItem = app.project.activeItem;

var selectedLayers = curItem.selectedLayers;

// check if comp is selected

if (curItem == null || !(curItem instanceof CompItem)){

// if no comp selected, display an alert

alert("Please establish a comp as the active item and run the script again");

} else {

// define the layer in the loop we're currently looking at

var curLayer = curItem.selectedLayers[0];

// check if that layer is a footage layer

if (curLayer.matchName == "ADBE AV Layer"){

// add a FILL COLOR

var myEffect = curLayer.Effects.addProperty("ADBE Fill");

myEffect.color.setValue([0.33529413938522,0.87653977274895,0.47653977274895,1]);

}

}

// close the undo group

app.endUndoGroup();

}

function MyFunction02()

{

// create an undo group

app.beginUndoGroup("AddEffect");

var curItem = app.project.activeItem;

var selectedLayers = curItem.selectedLayers;

// check if comp is selected

if (curItem == null || !(curItem instanceof CompItem)){

// if no comp selected, display an alert

alert("Please establish a comp as the active item and run the script again");

} else {

// define the layer in the loop we're currently looking at

var curLayer = curItem.selectedLayers[0];

// check if that layer is a footage layer

if (curLayer.matchName == "ADBE AV Layer"){

// add a FILL COLOR

var myEffect = curLayer.Effects.addProperty("ADBE Fill");

myEffect.color.setValue([0.63529413938522,0.27653977274895,0.27653977274895,1]);

}

}

// close the undo group

app.endUndoGroup();

}

//================= SHOW UI============

    fenetre.layout.layout(true);

    fenetre.layout.resize();

    fenetre.onResizing = fenetre.onResize = function () {fenetre.layout.resize()};

    if (fenetre != null ) if (fenetre instanceof Window) fenetre.show();

    }

FILL(this);

Adobe Community Professional
Correct answer by Tomas_Sinkunas | Adobe Community Professional

Change this:

FillButton01.onClick = function Choix() {

    if (CheckButton.value == false) {

        FillButton01.onClick = MyFunction01

    } else {

        FillButton01.onClick = MyFunction02

    }

};

To this:

FillButton01.onClick = function () {

    CheckButton.value == false

        ? MyFunction01()

        : MyFunction02();

}

TOPICS
Scripting

Views

663

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Checkbox Value

Community Beginner ,
May 17, 2017

Copy link to clipboard

Copied

Hello ,i am trying to ,with one button and a checkbox to switch between two functions.

But when i check the value of this checkbox ,at the first use,it works ,but then, when i change it,

it's always the value i use at the begining .

So i dont know how to verify after each click the new value of my checkbox ??

Here is my code ,if somebody has an idea..

Thank you everyone

function FILL(obj)

//===============================================

    //================= UI============================

    //===============================================

   

  {

       

    function addHGroup(conteneur){

  var groupe = conteneur.add("group");

  groupe.alignChildren = ["fill","fill"];

  groupe.orientation = "row";

  groupe.spacing = 1;

  groupe.margins = 0;

  return groupe;

    }

    function addVGroup(conteneur){

        var groupe = conteneur.add("group");

        groupe.alignChildren = ["fill","fill"];

        groupe.orientation = "column";

        groupe.spacing = 1;

        groupe.margins = 0;

        return groupe;

    }

            

    var fenetre = obj instanceof Panel ? obj : new Window("window","BS_TOOLS",undefined,{resizeable:true});

    fenetre.alignChildren = ["fill", "top"];

    fenetre.spacing  = 2;

    fenetre.margins = 2;

   

   

    var fillGroup01 = addHGroup(fenetre);

    fillGroup01.alignment = ["fill","top"];

    var FillButton01 = fillGroup01.add("button",undefined,"FILL"); 

 

   

    var fillGroup02 = addHGroup(fenetre);

    fillGroup02.alignChildren = ["fill","center"];

    var CheckButton = fillGroup02.add("checkbox",undefined,"Other Color?");

    CheckButton.size = [100,25];

  

   

   

//CLICK_______________________________________________________________________________

FillButton01.onClick=function Choix() {if (CheckButton.value==false) {FillButton01.onClick=MyFunction01}else{FillButton01.onClick=MyFunction02}};

//FUNCTIONS ____________________________________________________________________

  

   

   

    function MyFunction01()

{

// create an undo group

app.beginUndoGroup("AddEffect");

var curItem = app.project.activeItem;

var selectedLayers = curItem.selectedLayers;

// check if comp is selected

if (curItem == null || !(curItem instanceof CompItem)){

// if no comp selected, display an alert

alert("Please establish a comp as the active item and run the script again");

} else {

// define the layer in the loop we're currently looking at

var curLayer = curItem.selectedLayers[0];

// check if that layer is a footage layer

if (curLayer.matchName == "ADBE AV Layer"){

// add a FILL COLOR

var myEffect = curLayer.Effects.addProperty("ADBE Fill");

myEffect.color.setValue([0.33529413938522,0.87653977274895,0.47653977274895,1]);

}

}

// close the undo group

app.endUndoGroup();

}

function MyFunction02()

{

// create an undo group

app.beginUndoGroup("AddEffect");

var curItem = app.project.activeItem;

var selectedLayers = curItem.selectedLayers;

// check if comp is selected

if (curItem == null || !(curItem instanceof CompItem)){

// if no comp selected, display an alert

alert("Please establish a comp as the active item and run the script again");

} else {

// define the layer in the loop we're currently looking at

var curLayer = curItem.selectedLayers[0];

// check if that layer is a footage layer

if (curLayer.matchName == "ADBE AV Layer"){

// add a FILL COLOR

var myEffect = curLayer.Effects.addProperty("ADBE Fill");

myEffect.color.setValue([0.63529413938522,0.27653977274895,0.27653977274895,1]);

}

}

// close the undo group

app.endUndoGroup();

}

//================= SHOW UI============

    fenetre.layout.layout(true);

    fenetre.layout.resize();

    fenetre.onResizing = fenetre.onResize = function () {fenetre.layout.resize()};

    if (fenetre != null ) if (fenetre instanceof Window) fenetre.show();

    }

FILL(this);

Adobe Community Professional
Correct answer by Tomas_Sinkunas | Adobe Community Professional

Change this:

FillButton01.onClick = function Choix() {

    if (CheckButton.value == false) {

        FillButton01.onClick = MyFunction01

    } else {

        FillButton01.onClick = MyFunction02

    }

};

To this:

FillButton01.onClick = function () {

    CheckButton.value == false

        ? MyFunction01()

        : MyFunction02();

}

TOPICS
Scripting

Views

664

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
May 17, 2017 0
Adobe Community Professional ,
May 17, 2017

Copy link to clipboard

Copied

Change this:

FillButton01.onClick = function Choix() {

    if (CheckButton.value == false) {

        FillButton01.onClick = MyFunction01

    } else {

        FillButton01.onClick = MyFunction02

    }

};

To this:

FillButton01.onClick = function () {

    CheckButton.value == false

        ? MyFunction01()

        : MyFunction02();

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 17, 2017 0
Engaged ,
May 18, 2017

Copy link to clipboard

Copied

As Tomas says, you should be calling the functions rather than assigning them to the onClick behaviour (although you're fine to use the full if / else rather than the needlessly unclear ? : in his example). Presumably what's happening is you're redirecting the onClick away from "Choix" after the first time, so then it will never come back through that and forever be stuck on the first reassigned function.

The alternative would be to have the whole function be a CheckButton.onClick function, where that assigned the onClick behaviour of what happens when FillButton01 is clicked, although I've never done it that way myself. I rarely change the assigned onClick behaviour from that which I setup initially with my UI.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 18, 2017 0
Community Beginner ,
May 18, 2017

Copy link to clipboard

Copied

Thank you guys for you help ,it works fine..

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 18, 2017 0