Wrapping Up

Before we leave the subject of automating animation and buttons for fixed layout EPUB we will look at a few topics which we have purposely left for last: Changing Color and Rollover behavior.

Changing Color

One thing that you cannot do as part of animating an object is to change its color. Short of setting up a multi-state object, you can make the animation of your spread look like a page item changes its color when some event triggers its animation. This is done by animating two identical objects having different colors. We will see how this is done by creating a simple test script. But first, we will set up a script template that can act as a starting point for all of our test scripts.

Animation Starter Template

For simplicity, the template assumes that there is a document open set for web intent. Web intent changes the measurement system to pixels and the page orientation to landscape. It also sets the Document RGB Transparency Blend Space and installs RGB default swatches. Make sure that the RGB default swatches include the following: Red, Blue, Green and Purple. The script will make sure that measurement units for the document are set to points and that the ruler is set to page origin.

AnimationStarter

   tell application "Adobe InDesign CC 2014"
      set docRef to document 1
      tell docRef
         set spreadRef to spread 1
         set horizontal measurement units of view preferences to points
         set vertical measurement units of view preferences to points
         set ruler origin of view preferences to page origin
      end tell
      --Add code to create page items and animation properties here
      --set timing settings
      tell timing settings of spreadRef
         if  (count of timing lists) is greater than 1 then
            delete timing list 1
         end if
         --add timing list(s) and timing groups here
      end tell --spread timing settings
   end tell --application

Save Template

If you have a later version of iOS and administrator privileges, you may want to save the AnimationStarter code as a template. Yes, script templates is a new and exciting addition for Script Editor. If you see New From Template in Script Editor’s File menu, create a folder for your script templates in the following file path:

   Library/Application Support/Script Editor/Templates

Save your script template there. With this in place you can start a new script from Script Editor’s File Menu > New From Template. Simply choose the folder and template from the flyout menu lists.

New Script From Template

Otherwise, to start a new script, just copy the template to a new script.

Using the template, create a script to set up a test for changing color by adding the following to the new script started with the template:

At the top of the script:

   set rectBounds to {72, 72, 144, 144}

In the section where the comment begins –Add code to…

   tell spreadRef
      set blueRect to make rectangle with properties {name:"blueRect", geometric bounds:rectBounds, fill color:"Blue", stroke color:"None"}
      set properties of animation settings of blueRect to {duration:1, opacity array:{{0, 0}, {23, 100}}}
      set redRect to make rectangle with properties {name:"redRect", geometric bounds:rectBounds, fill color:"Red", stroke color:"None"}
      set properties of animation settings of redRect to {duration:1, opacity array:{{0, 100}, {23, 0}}}
   end tell

After –add timing list(s) and timing groups here

   set clickTimingList to make timing list with properties {trigger event:on page click}
      tell clickTimingList
	set rectTimingGroup to make timing group with properties {dynamic target:blueRect, delay seconds:0}
      tell rectTimingGroup
	make timing target with properties {dynamic target:redRect, delay seconds:0}
      end tell --timing group
   end tell --timing list

Compile the script and run with a new InDesign document open. Make sure the colors “Blue” and “Red” are established in the document. After running the script your document should have a red square on the first page.

View the animation in the EPUB Interactivity Preview panel. Click the run button (triangle) bottom left. When the page displays in the window, click the page to see the animation. (The color of the square should change from red to blue.)

When you are successful, continue on to test some rollover behaviors.

Rollover

When the mouse pointer passes over a button or an object, we say that the object has been rolled over. Our next test will demonstrate how a script can be written to animate a page item when the page item is rolled over. Start with your template created above.

Add the following at the top:

   set rectBounds to {72, 72, 144, 144}
   set outBounds to {60, 60, 156, 156}

In the section where the comment begins –Add code to create page items…

   tell spreadRef
      set frameOutline to make rectangle with properties {name:"outline", geometric bounds:outBounds, fill color:"None", stroke color:"Black"} 
      set rectRef to make rectangle with properties {name:"rollOver", geometric bounds:rectBounds, fill color:"Red", stroke color:"None"}
      set properties of animation settings of rectRef to {duration:1, opacity array:{{0,0}, {23, 100}}}
   end tell

After –add timing list(s) and timing groups here

   set loadList to make timing list with properties {trigger event:on page load}
   tell timing settings of rectRef
      set rectTimingList to make timing list with properties {trigger event:on self rollover}
   end tell

Notice that rectTimingList is created as an element of the timing settings for the rectangle.

Compile and test the script with a new document open. Make sure the document has the RGB colors “Red” and “Black” in the swatches panel.

When the script is run, notice (as in the screen capture below) that the red square is visible in the document but not visible in the EPUB Interactivity Preview panel. When you pass the mouse pointer over the area inside the black outline, the square becomes visible. The behavior repeats every time the area is rolled over.

    Preview of page before rollover animation

When you are successful, continue on to see how a button can target other page items when rolled over.

Button Rollover Behavior

We have seen that a button can trigger the animation for another object when clicked. This can also be done when the button is rolled over. This is accomplished through animation behaviors.

Animation Behaviors

Animation behaviors are elements of buttons, and form widgets. When we set up a button to animate a page item, the script needs to create an animation behavior for the button. To see how this works, we will create a test script that creates a button and have it animate a page item when the user moves the pointer over the button. Interestingly, for a button this is not called a rollover event but a mouse enter. When the mouse pointer leaves, the event is referred to as a mouse exit.

Start a new script using the template created above.

At the top of the script add:

   set buttonBounds to {72, 72, 108, 144}
   set rectBounds to {72, 200, 172, 300}

In the Section where the comment begins –Add code to create page items…:

   tell spreadRef
      set targetRect to make rectangle with properties {name:"Target", geometric bounds:rectBounds, fill color:"Red", stroke color:"None", stroke weight:0}
      set buttonRef to make button with properties {name:"Play It", geometric bounds:buttonBounds, fill color:"Green", stroke color:"Green", stroke weight:1}
   end tell
   tell animation settings of targetRect
      set properties to {duration:1, opacity array:{{0,0}, {23, 100}}}
   end tell
   tell buttonRef
      convert shape given convert to rounded rectangle corner radius 10
      make animation behavior with properties {behavior event: mouse enter, behavior:true, animated page item:targetRect, auto reverse on roll off:false, operation:play}
   end tell 

After –add timing list(s) and timing groups here

   set loadList to make timing list with properties {trigger event:on page load}

Compile and then run the script with a new document open. Make sure you have the RGB colors “Green” and “Red” in the document. When you view the result in the EPUB Interactivity Preview panel, you should see the button, but the square will not become visible until you pass the mouse pointer over the button. Each time you pass the pointer over, the animation repeats.

Preview before button is rolled over

Auto Reverse on Roll Off

You may be curious about the animation behavior property auto reverse on roll off. Documentation says that setting this property to true will cause the animation to reverse when the mouse pointer rolls off. In version 2014.1 of InDesign this only works when the animation is exported as Flash (SWF).

Onward and Upward

You have now been introduced to most of the basics having to do with page items and buttons. But, not to worry, there is still a lot of animation that can be added to your fixed layout EPUB. Make sure you understand all of the concepts that have been covered so far. We will be using all of these and many more in the future.