7

using extend script to push a variable into an array it's basically javascript. any idea what I am doing wrong?

if ( app.documents.length > 0 ) {

    for ( i = 0; i< app.activeDocument.textFrames.length; i++) {
         var allSizes = []; //set up empty array

        textArtRange = app.activeDocument.textFrames[i].textRange;
        var fontName =  textFonts.getByName("Nobile");
        alert (fontName);
        textArtRange.characterAttributes.textFont = fontName;
        var fontSizes = textArtRange.characterAttributes.size;

        allSizes.push(fontSizes)
        alert (fontSizes);

    }
        alert (allSizes);
}

the alerts for allSizes only return single values, not the array.

Lukasz
  • 926
  • 3
  • 14
  • 22

2 Answers2

13

Move the definition of allSizes = [] outside the loop.

Currently, you're "resetting" the value of allSizes at each loop.

Rob W
  • 341,306
  • 83
  • 791
  • 678
9

You're setting up the empty array inside of the for loop. It's resetting it each time. Move it above the for loop:

var allSizes = []; //set up empty array
for ( i = 0; i< app.activeDocument.textFrames.length; i++) {
     .....
Chris Eberle
  • 47,994
  • 12
  • 82
  • 119
  • 1
    wow, that was totally it. what a noob move, ha! can't believe i didn't see that. thanks! – Lukasz Oct 03 '11 at 18:10
  • 1
    @Lukasz: You need to accept an answer to this question. Do it by clicking the green checkmark next to the answer that helped you most. http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – Alex Turpin Oct 03 '11 at 18:28