2 Replies Latest reply on Jul 7, 2011 8:43 PM by John Hawkinson

    Placing images into a multistate object

    Napo Monasterio Level 1

      Hey folks,

       

      Trying to figure out what's going on here. Thanks to some helpful folks here, I'm making inroads with JS programming, but I'm still hitting some bumps in the road.

       

      I've got a handful of graphics that I'm importing, and now I want to to turn them into a multistate object. Here's what I'm doing:

       

      var tabletSlideshow = app.activeDocument;
      
      tabletSlideshow.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.PIXELS;
      tabletSlideshow.viewPreferences.verticalMeasurementUnits = MeasurementUnits.PIXELS;
      
      
      var slideshowImages = File.openDialog("Choose the images you want incuded", "Files:*.jpg", true);
       
      if((slideshowImages != "")&&(slideshowImages != null)){
      
      for (i=0; i<slideshowImages.length; i++)
      
      tabletSlideshow.pages.item(0).place(slideshowImages[i]);
        
      //get items for slideshow
      mySlideshow = tabletSlideshow.pageItems;
      app.select(mySlideshow);
      //this is where I get my errors
      tabletSlideshow.pages.item(0).pageItems(mySlideshow).multiStateObjects.add();
      
      //I've also tried this
      
      var myState = tabletSlideshow.pages.item(0).pageItem(mySlideshow).multiStateObjects.add();
      

       

      I know it's something silly, I just can't put my finger in it. I've managed to do:

       

      var myState = tabletSlideshow.pages.item(0).multiStateObjects.add();
      
      for (j=2; j<slideshowImages.length; j++)
      
      myState.states.add([j]);
      
      

       

      Which creates a new object state with the same number of states as graphics, but I'm not too sure of how to place the graphics inside each state.

       

      I know I'm making this way more complicated than it should be, and that's the problem. Any help would be much appreciated! Thanks in advance!

       

      N

        • 1. Re: Placing images into a multistate object
          Napo Monasterio Level 1

          Bump.

           

          Any ideas?

           

          Thanks!

           

          N

          • 2. Re: Placing images into a multistate object
            John Hawkinson Level 5

            I don't have any experience with multistate objects, but:

             

            for (i=0; i<slideshowImages.length; i++)
             
            tabletSlideshow.pages.item(0).place(slideshowImages[i]);
              
            //get items for slideshow
            mySlideshow = tabletSlideshow.pageItems;
            app.select(mySlideshow);

             

            You should indent your loops!

            You should not be accessing your page item via the document's .pageItems array. The place() method will return an array of objects that are placed, so you should set a variable equal to its return value and use that.

             

            Also:

             

            myState.states.add([j]);

             

            That's just wrong! j is a number from 2 to {something}, so [j] is an Array containing one element, the number j. That cannot be what you want to pass to State.add(), which takes an object full of properties to add.

             

            Anyhow, back to your problem:

             

            //this is where I get my errors
            tabletSlideshow.pages.item(0).pageItems(mySlideshow).multiStateObjects.add();
            

             

            Why would this work? a PageItem does not have a multiStateObjects property. And it wouldn't make sense for it to do so -- a MultiStateObject is not contained within a PageItem! It is a type of PageItem. (Though it appears to be contained within some pageitems, like Rectangle, but let's not worry about that).

             

            So, if you want to add a new MultiStateObject, you'll have to add it to a page or a spread or something. Such as with

             

            var myMSO = tabletSlideShow.pages[0].multiStateObjects.add();
            

             

            Then you probably want to call the addItemsAsState() method on your MSO, with the placed item as the parameter.