Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Pay attention to my #3rd step - you are adding iconButtons into an array of buttonsRow[i], that most likely throws an error.
Copy link to clipboard
Copied
That was the problem.
But turning buttonsRow[i] and evaling it solved my problem.
Copy link to clipboard
Copied
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',
});
}
});
Copy link to clipboard
Copied
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
Find more inspiration, events, and resources on the new Adobe Community
Explore Now