Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

ListItem <=> Array (ExtendScript)

Participant ,
Aug 06, 2020 Aug 06, 2020

I'm trying to use a selection from a multiline listbox as arguments in a function, but It does not work.

If I'm testing it with an static array as test-argument everything works fine -  the testing structure tells me that it is an array and tells me "yes" when I ask it if it contains "Element 2" (var selectableTypes as argument instead of myDropdown.selection).

 

But if I send a ListItem it tells me it is an array but "no" at the test afterwards.

Corvin0_1-1596717030511.pngexpand imageCorvin0_2-1596717041269.pngexpand image

 

 

And If I add another test asking for array elements 0 and 1, it crashes completely with this error:

Corvin0_0-1596716866557.pngexpand image

 

Remember, that it told me it IS an array before, but it looks like it is not one at the same time...I'm confused 😉

 

myPanel = new Window ('dialog {orientation:"row"}'); 

var selectableTypes = ["Element 1","Element 2","Element 3"];

// UI ************************************
var myGrp = myPanel.add('group {orientation:"row", alignChildren:"fill"}');
var myDropdown = myGrp.add("listbox", [0,0,200,200], selectableTypes, {scrolling: true, multiselect: true});
var myButton = myGrp.add("button",[0,0,100,20],"Select");
//****************************************

myButton.onClick = function (){selectLayers(myDropdown.selection);}
function selectLayers(mySelection){
alert (mySelection[0]+" and "+mySelection[1]); // This test breaks it with the ListItem!
  
 if(mySelection.constructor === Array){ alert ("Is Array");  } else  { alert("Not an Array");} // Ergebnis: Is Array
  
    if(mySelection.indexOf("Element2") > -1){ // Select by Type
        alert(" YES");
        }else {
            alert(" NO");
            }
       }

myPanel.center();
myPanel.show();

 

TOPICS
Error or problem , How to , Scripting
525
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , Aug 06, 2020 Aug 06, 2020

So, only 10 minutes later and I found it out by myself. But I thought maybe someone finds it helpful to know, what the problem was:

 

List items ARE Arrays. But to access the items one has to use the property "text":

 

 

 

function selectLayers(mySelection){
  
 if(mySelection.constructor === Array){ alert ("Is Array");  } else  { alert("Not an Array");} // Ergebnis: Is Array
  
  for(i=0;i<mySelection.length;i++){
    if(mySelection[i].text.indexOf("Element 2") > -1){ // Select by Type
        alert(
...
Translate
Participant ,
Aug 06, 2020 Aug 06, 2020
LATEST

So, only 10 minutes later and I found it out by myself. But I thought maybe someone finds it helpful to know, what the problem was:

 

List items ARE Arrays. But to access the items one has to use the property "text":

 

 

 

function selectLayers(mySelection){
  
 if(mySelection.constructor === Array){ alert ("Is Array");  } else  { alert("Not an Array");} // Ergebnis: Is Array
  
  for(i=0;i<mySelection.length;i++){
    if(mySelection[i].text.indexOf("Element 2") > -1){ // Select by Type
        alert(i+" YES");
        }else {
            alert(i+" NO");
            }
       }
}

 

 

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