Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions dropdown interaction issue…

  • dropdown interaction issue…

    Posted by Fabio Apelbaum on May 13, 2016 at 7:32 pm

    Hi guys,

    I have a composition with 48 layers, and I decided to separate them all in groups of 12 layers depending on its properties (with or without logo or bar)… See image attached.

    Anyways, the dropdowns works good, when I select an item of one of the dropdowns, it makes that one layer visible and disable all the other layers…

    Where I am having problems is, I want my user interface to only show the selected layer within the dropdown and have the other three dropdowns show blank or dd.selection=0.

    So I added to each dropdown the following:

    //SELECT DROPDOWN A
    ddA.onChange = function() {
    ddB.selection = 0; //I also tried changing 0 for null; and same problem.
    ddC.selection = 0;
    ddD.selection = 0;

    Additional code…
    };
    //SELECT DROPDOWN B
    ddB.onChange = function() {
    ddA.selection = 0; //I also tried changing 0 for null; and same problem.
    ddC.selection = 0;
    ddD.selection = 0;

    Additional code…
    };

    //SELECT DROPDOWN C
    ddC.onChange = function() {
    ddA.selection = 0; //I also tried changing 0 for null; and same problem.
    ddB.selection = 0;
    ddD.selection = 0;

    Additional code…
    };

    //SELECT DROPDOWN D
    ddD.onChange = function() {
    ddA.selection = 0; //I also tried changing 0 for null; and same problem.
    ddB.selection = 0;
    ddC.selection = 0;

    Additional code…
    };

    The problem is that it is not just changing the selection on my GUI, but is triggering the other three dropdowns .onChange event, even if I am not using notify() which causes the dropdowns to conflict between all of them. Is there a way to tell it that when the user selects one option from one of the dropdowns to make the other dropdown to show the first item on their list which is ” ” without triggering the .onChange of the additional dropdowns?

    Thanks in advance for the help!

    Fabio

    Xavier Gomez replied 10 years ago 2 Members · 3 Replies
  • 3 Replies
  • Xavier Gomez

    May 13, 2016 at 8:09 pm

    To set a dropdown selection without triggering its onChange event, you can temporarily either delete the onChange handler (javascript delete), or assign to it the undefined value, or assign to it a dummy onChange that does nothing.
    For instance, this would work i think (set dummy onChange):

    var dds = [ddA, ddB, ddC, ddD];
    for (var i=0; i<4; i++) dds[i].onChange = onDDchange;

    function noop(){};
    function onDDChange(){
    for (var i=0; i<4; i++){
    if (dds[i] == this){
    // stuff to do for the dropdown which is been changed
    /*your stuff*/
    }
    else if (dds[i].selection !== null){
    // stuff to do for other dds : reset selection to null
    dds[i].onChange = noop;
    dds[i].selection = null;
    dds[i].onChange = onDDChange;
    };
    };
    };

    Replacing the line dds[i].onChange = noop; by
    dds[i].onChange = void 0;
    or by:
    delete dds[i].onChange;
    would work too.

    However i dont know a direct way to set a dd’s selection without triggering.

    Xavier

  • Fabio Apelbaum

    May 16, 2016 at 3:28 pm

    Xavier! thank you so much, it works great!

    Let me ask you a question to better understand whats going on,

    when I read:

    var dds = [ddA, ddB, ddC, ddD];
    for (var i=0; i<4; i++) dds[i].onChange = onDDChange;

    why is that onDDChange not using parentheses? onDDChange() if it is related to the function?

    Thanks again!!

    Fabio

  • Xavier Gomez

    May 16, 2016 at 4:00 pm

    onDDchange is the function itself, while onDDchange() is its result (which is undefined since the function returns nothing).
    You want to assign the function, not its result.

    After i answered you i came across this article:
    https://www.davidebarranca.com/2013/09/scriptui-tip-decoupling-components-event-handling/.
    It might interest you. As far as i’m concerned, bubbling or no bubbling gives me headaches, i actually use code similar to the one in my answer and i’m fine with it.

    Xavier

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