Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Custum UI button onClick don’t work???

  • Custum UI button onClick don’t work???

    Posted by Taras Kosmachuk on March 29, 2015 at 11:41 pm

    Hi! Can someone help me to solve my problem, please!

    The problem is that when I run my script it executes functions assigned to buttons all at once and then all buttons except “Button 3” with alert stop working. Why is this happening?

    Thanks in advance!

    // Global Variables
    var _comp = app.project.activeItem;

    { // Build UI
    function UI(thisObj){
    function buildUI(thisObj){
    var uiPanel = (thisObj instanceof Panel) ? thisObj : new Window("palette", "new project", undefined, {resizeable:true});

    var res = "group{ orientation: 'column', \
    group1: Group { orientation: 'column', \
    bt1: Button{ text: 'Button 1' }, \
    }, \
    group2: Panel { text: 'Panel', orientation: 'column', alignChildren: ['fill', 'fill'], margins: ['20', '15', '20', '15'], spacing: '10', \
    bt2: Button{ text: 'Button 2', preferredSize: ['150', '30'] }, \
    bt3: Button{ text: 'Button 3', preferredSize: ['-1', '30'] }, \
    bt4: Button{ text: 'Null', preferredSize: ['-1', '20'] }, \
    stName: StaticText{ text:'Name:', alignment: ['left', 'center'] }, \
    etName: EditText{}, \
    bt5: Button{ text: 'Button 5', preferredSize: ['-1', '20'] }, \
    }, \
    }";

    uiPanel.grp = uiPanel.add(res);

    // Declare functions for Buttons
    var BT1 = uiPanel.grp.group1.bt1;
    var BT2 = uiPanel.grp.group2.bt2;
    var BT3 = uiPanel.grp.group2.bt3;
    var BT5 = uiPanel.grp.group2.bt5;

    BT1.onClick = f1();
    BT2.onClick = f2();
    BT3.onClick = function() { alert(":)"); };
    BT5.onClick = f3();

    // Setup size and resizing
    uiPanel.layout.layout(true);
    uiPanel.grp.minimumSize = uiPanel.grp.size;
    uiPanel.layout.resize();
    uiPanel.onResizing = uiPanel.onResize = function() { this.layout.resize(); };

    return uiPanel;
    }

    var scriptUI = buildUI(thisObj);
    if ((scriptUI |= null) && (scriptUI instanceof Window)){
    scriptUI.center();
    scriptUI.show();
    }
    }

    UI(this);
    }

    function f3() {

    var numL = _comp.numLayers;

    app.beginUndoGroup("03");
    for (i = 1; i <= numL; i++) {
    _comp.layer(i).inPoint = 0;
    _comp.layer(i).outPoint = 1;
    _comp.layer(i).startTime = i - 1;
    }
    app.endUndoGroup();

    }

    function f2() {
    app.beginUndoGroup("b2");

    var sLayers = _comp.selectedLayers;

    for (s = 1; s <= sLayers.length; s++) {
    var dLayer = sLayers[s - 1].duplicate();
    }

    app.endUndoGroup();
    }

    function f1() {
    app.beginUndoGroup("b1");

    var newL = _comp.layers.addNull();
    newL.name = "New Layer";

    app.endUndoGroup();
    }

    Taras Kosmachuk replied 11 years, 1 month 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