Saving the State of SWF Content in Acrobat 9

| 5 Comments

Skip down to here if you read my last post

The Basics of SWF in PDF
One of the great new features of Adobe Acrobat 9 Pro and Pro Extended is the ability to add interactive SWF content developed in Flash or Flex. SWF files can be placed in a PDF using the new Flash Tool in Acrobat 9 and play using the built in Acrobat 9 Flash Player rather than the external one that your browser and desktop use. The built-in player provides greater security and consistency for SWF playback inside any PDF with that type of content. For those of you that attempted to use SWF in earlier versions of Acrobat, you remember that the user experience wasn’t all that great. Acrobat 9 provides tight integration between the PDF document and SWF as well as other content types that run in the Flash Player such as FLV and H.264 encoded video.

Read “Add multimedia files to a PDF” to learn how to add SWF content to PDF files using the new Rich Media Annotation rather than the legacy multimedia object.

Saving the State of SWF Content in Acrobat 9
In addition to the built-in Flash player providing greater security and consistency for SWF playback, it also has built in functions that take advantage of features found only in Acrobat and Reader. The remainder of this article discusses how to keep the state of your SWF content persistent in the PDF so that when the file is saved then reopened, your SWF content looks the same.

To store the state of your SWF content, use the built in "multimedia_saveSettingsString" function
and pass in a string that contains all of the variables you need to recreate the state you are saving.
In the example file below, I’m simply storing the value of the HSlider called "size". For more complex applications, I recommend using an XML object to store the variables and then casting it to a string before saving it.
I also recommend saving the state every time a variable that you want to track gets changed. Acrobat will fire a "WillSave"
event that you can attach JavaScript to that can be used to call the "multimedia_saveSettingsString" but the internal
plumbing must be added to the PDF for that to work. By saving the settings on every change, all of the work can be done in ActionScript rather than a combination of ActionScript and JavaScript.

var result:Object = ExternalInterface.call("multimedia_saveSettingsString", size.value.toString());

Restoring the State of SWF Content in Acrobat 9
To resore the settings, add code that uses the built in function "multimedia_loadSettingsString" to the creationComplete function.
In the example code below, if the widget was just placed and settings were never saved (result returns null), it uses the defaults programmed into the application.
If the call returns an object, I use it to restore the state. Again, for more complex use cases, an XML object that is cast as a string can be used.

var result:Object = ExternalInterface.call("multimedia_loadSettingsString");
if (result)
{
size.value = int(result.toString());
}

Open the example PDF below and move the slider to adjust the size of the red square. Save the file. Close it, then reopen it. You’ll see that the size of the red square is the same as it was when you saved the file.

  Example PDF

Sample Flex Application