Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Extendscript: Dropdownlist selection is set by integer, but returns a string..?

  • Extendscript: Dropdownlist selection is set by integer, but returns a string..?

    Posted by Adam Smith on March 19, 2015 at 6:31 pm

    I’ve created a gui for an aftereffects tool I’m working on and I’d like to save the state of a dropdown list to a default. The problem I’m having is to set the selection for mydropdown list, I have to use an integer index. But when I retrieve the value, it returns a string. I need the data types to be the same so that I can save the state of the dropdown as a default. So far all of my experiments have failed..

    Thanks for any help

    Adam

    mydropdownlist.selection=1 //set the property with an integer
    alert(typeof mydropdownlist.selection) //the same property returns a string

    Dan Ebberts replied 11 years, 1 month ago 4 Members · 5 Replies
  • 5 Replies
  • Xavier Gomez

    March 19, 2015 at 7:09 pm

    The selection of a dropdownlist is a ListItem or null, so in any case, typeof mydropdownlist.selection should be “object”.
    In the console: $.writeln(mydropdownlist.selection) will be either “null” or the selected item text property (not its index). The string is not the selection itself, it is a display string for the selection.

    And to set the selection you can do either of:

    // selection by index:
    dd.selection = dd.items[0];
    dd.selection = 0;

    // selection by text (it will be the first item that carry that text, or null if not found)
    dd.selection = dd.find(someText);

    And may be some other ways.

    Xavier

  • Adam Smith

    March 19, 2015 at 9:47 pm

    Thanks Xavier!

    I guess I was assuming the selection was a string since it showed up as text last night when I was messing with it. I should have double checked before I posted my code from memory.

    dd.find(someText); was what I was looking for.

    Thanks again

  • Adam Smith

    March 20, 2015 at 5:21 pm

    In case this helps anyone else, this returns an integer:

    mydropdownlist.selection.index

  • Fabio Apelbaum

    March 29, 2015 at 4:04 pm

    Hi Xavier! I see you have wide experience with Dropdownlist. Let me ask you a question as well. I have an after effects project with a composition loaded with team logos. I was able to create a Dropdownlist that will automatically gather the names of the layers to populate the drop down list.

    then, the scripts requests to all layers be disabled so when one is selected from the drop down, only the selected team becomes enabled. This is what I am having problems with, I’m not sure how to connect this part of the script with the Dropdownlist so it recognizes the selected team to enable it.

    Here is the script:
    The ?????? is what I believe its missing for it to work, not sure what to write there:

    var myWin = new Window(“palette”, “Drop down list”, undefined);
    var proj = app.project;
    var awayComp = proj.item(2);
    var homeComp = proj.item(3);
    var myList = new Array();

    for(var i=1; i <= awayComp.numLayers; i++){
    myList[myList.length] = awayComp.layer(i).name;
    }

    var groupOne = myWin.add(“group”, undefined, “GroupOne”);
    var dd = groupOne.add(“dropdownlist”, undefined, myList);
    dd.selection = 0;

    dd.onChange = function() {

    for(var i = 1; i < awayComp.layers.length +1;i++){
    //Hides all visible layers
    awayComp.layer(i).enabled = awayComp.layers.enable = false;
    // check name
    if(awayComp.layers[i].name == ?????? {
    // turn into opposite
    awayComp.layers[i].enabled = !awayComp.layers[i].enabled;
    }
    }
    };

    myWin.center();
    myWin.show();

    Hope it makes sense!

    Please, I will truly appreciate all your help!

  • Dan Ebberts

    March 29, 2015 at 5:07 pm

    I think this might be what you’re looking for:

    this.selection.text

    Dan

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