3 Replies Latest reply on Jul 4, 2013 1:04 AM by richardhauck

    document.pages is "null"

    richardhauck

      Hi everybody

       

      I'm just writing a InDesign CS6 PlugIn with Adobe Flash Builder/ CS Extension Builder. So I hope this would be the rightplace to ask this question.

       

      Before I wrote a couple JacaScripts for InDesign and it alwas worked like this to get all pages from my Document as a Array like this:

       

      var test:Page = app.activeDocument.pages[0];
      

       

      app would be my InDesign Application.

       

      Now I get the correct number of pages with pages.length, but there is no array with all my pages-objects.

       

      Does anybody know what's wrong? The API says that there schould be th Collection of pages with this code.

      Thanks for any help on this.

      Best Richard

        • 1. Re: document.pages is "null"
          Harbs. Level 6

          You are mixing up Arrays and Collections.

           

          Almost all sets of DOM objects are returned as collections and not Arrays. (Some exceptions are allPageItems -- or anything else that starts with all or textConainers.) Document.pages is a collection. To iterate through the collection you should use myCollection.item(index). To convert a collection to an Array (which you might want to do for performance reasons), you use myCollection.everyItem().getElements().

           

          HTH,

          Harbs

          • 2. Re: document.pages is "null"
            Harbs. Level 6

            In Javascript, brackets work as shorthand for item(), so app.activeDocument.pages[0] is the same as writing
            app.activeDocument.pages.item(0), but that does not work in Actionscript.

            • 3. Re: document.pages is "null"
              richardhauck Level 1

              Hi Harbs

               

              Thanks for the clarification. As it always worked with Arrays in JavaScript I didn't look forther as the API talks about a Collection. Now it works perfectly and I learned to read better ;-)

               

              Richard