Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Possible to make a iconbutton that toggles its image?

  • Possible to make a iconbutton that toggles its image?

    Posted by Crystal Goh on August 14, 2020 at 8:48 am

    Currently having issues in making a toggle iconbutton with onClick(),

    here’s what I have

    var img1 = image 1's file path
    var img2 = image 2's file path

    // v - just the UI
    (function(thisObj) {

    scriptBuildUI(thisObj)

    function scriptBuildUI(thisObj) {
    var win = (thisObj instanceof Panel) ? thisObj : new Window("palette", "Expression2button_V01.2", undefined, 0);

    var button = win.add("iconbutton",[0,0,30,30],img1);

    //----

    button.onClick = function(){
    if(button.image = img1){
    button.image = img2;
    }else{//problematic part, after the 1st onClick and the image changes to img2, when you click again it doesn't go to this else statement
    button.image = img1;
    }

    //UI end code v --
    win.onResizing = win.onResize = function() {
    this.layout.resize();
    };

    win instanceof Window
    ? (win.center(), win.show()) : (win.layout.layout(true), win.layout.resize());
    }

    })(this);
    ===================================

    found a fix, had to make a state by using boolean

    var butState = true;

    button.onClick = function(){
    if(butState){
    button.image = img2;
    butState = false;
    }else{
    button.image = img1;
    }

    Crystal Goh replied 6 years ago 1 Member · 0 Replies
  • 0 Replies

Sorry, there were no replies found.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy