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

undefined is not an object

Participant ,
Feb 13, 2020 Feb 13, 2020

I'm creating buttons. After failing trying to figure how to use resize(). I've decided to stick with my current code, but trying to tidy it.

This works fine

var b = new Array();

for(var i = 0; i <= 3; i++ ){

var f = File (file[i].name);

b[i] = buttonsRow0.add ("iconbutton", undefined, f, {style: "toolbutton"});

}

But I want this to work and it keeps firing back "undefined is not an object"

var b = new Array();

for(var i = 0; i <= 3; i++ ){

var f = File (file[i].name);

b[i] = buttonsRow[i].add ("iconbutton", undefined, f, {style: "toolbutton"});

}

 

I've have tried numerous avenues with braces, squarebraces treating it as a variable. But nothing. If I physically type in 0,1,2,3. Works fine, if I use i. It doesn't.

Any ideas?

TOPICS
Error or problem , Expressions , Scripting
3.5K
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
Advocate ,
Feb 13, 2020 Feb 13, 2020

Can you be more specific? What line throws an error?

1. On line 3, why are you assigning a file name to a variable, when you should assign a FIle object? var f = new File(file[i]);

2. Is file variable an array containing 4 or more existing files (line 3)?

3. Are you sure you are using buttonsRow[i].add(/.../) properly? Shouldn't it be buttonsRow.add(/.../)

4. Is buttonsRow actually a Group or Panel object?

 

It's hard to pint point the issue without seeing the entire code.

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
Participant ,
Feb 13, 2020 Feb 13, 2020

Cheers Tomas for responding

1:  var f = File ("/Volumes/Server/Video/CAPi RenderBot Source/Logos/"+folder1[i].name); 

Is the actual line, but I guess it makes no difference it's nothing private. This get's my png file from a folder.

 

var myFolder = Folder("/Volumes/Server/Video/CAPi RenderBot Source/Logos/"); var folder1 = myFolder.getFiles("*.png").sort();

 

2: it is an array, of a folder with images. I'm just using 0-3 to test.

 

3: ButtonsRow is myPanel, I got this code way way ago and basterdised it.

var buttonsRow = myPanel.add("group", undefined, "");

buttonsRow.orientation = 'column';

var buttonsRow0 = buttonsRow.add("group", undefined, "");

var buttonsRow1 = buttonsRow.add("group", undefined, "");

var buttonsRow2 = buttonsRow.add("group", undefined, "");

var buttonsRow3 = buttonsRow.add("group", undefined, "");

var buttonsRow4 = buttonsRow.add("group", undefined, "");

var buttonsRow5 = buttonsRow.add("group", undefined, "");

var buttonsRow6 = buttonsRow.add("group", undefined, "");

buttonsRow1.orientation = buttonsRow2.orientation = buttonsRow3.orientation = buttonsRow4.orientation = buttonsRow5.orientation = buttonsRow6.orientation = buttonsRow0.orientation ='row';

I managed to get it to work using eval()

var b = new Array(); for(var i = 0; i <= 15; i++ ){ var f = File ("/Volumes/Server/Video/CAPi RenderBot Source/Logos/"+folder1[i].name); var str = "buttonsRow" + (Math.floor(i/5)); var n = eval(str); b[i] = n.add ("iconbutton", undefined, f, {style: "toolbutton"}); }

I prefer it to autolayout based on resize(), but the code seriously is way way above me. I've just looked at what you sent and my brain turned into a big puddle.

 

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
Advocate ,
Feb 13, 2020 Feb 13, 2020

Pay attention to my #3rd step - you are adding iconButtons into an array of buttonsRow[i], that most likely throws an error.

 

 

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
Participant ,
Feb 13, 2020 Feb 13, 2020

That was the problem. 

But turning buttonsRow[i] and evaling it solved my problem. Screenshot 2020-02-13 at 15.01.55.png

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
Advocate ,
Feb 13, 2020 Feb 13, 2020

Try this

var buttons = [];
var folder = new Folder("/Volumes/Server/Video/CAPi RenderBot Source/Logos/");
folder.getFiles(function(file) {
	if (file.fsName.split('.').pop() === 'png') {
		buttons[i] = buttonsRow.add('iconbutton', undefined, file, {
			style: 'toolbutton',
		});
	}
});
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
Participant ,
Feb 13, 2020 Feb 13, 2020
LATEST

Ah, I see. My bad in communication.

Your code would work fine, but I want it to add 5 buttons per Row. That was my problem. The above that you wrote would work absolutely fine. It would put all my pngs (43 currently) on one row.

Hences looking for it to adapt based on resize or to create a new row after every 5 icon buttons or what number I choose it to be.

But I will check out the link you sent. Really appreciate that, as I couldn't find anything on resize

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