These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

SWF embeded PDF - Save & READ a string

Mugsy
Registered: Feb 23 2010
Posts: 3
Answered

I reviewed : http://blogs.adobe.com/pdfdevjunkie/2008/08/saving_the_state_of_swf_conten.php
I really helped, but...

I am writting an flash app where the user can rearange objects on an board.
The user can save the current configuration by pressing a Save button.
He can also reload a SAVED configuration by pressing a RELOAD button.

When he reuses the app he expects to see the last saved state.

No problem saving.
On startup of the app, my read fails.
I have tried using the Event.INIT and Event.COMPLETE messages

stage.addEventListener(Event.COMPLETE, myCheckComplete);

INIT, occurs , then COMPLETE.

In myCheckComplete call Readit(), where I attempt to read the stored data.
This call is unsuccessful.

When I click on a Reload button my read works.
I believe my problem is in the timming.

Is there an EVENT I should be monitoring from ACROBAT telling me, everything is OK now, you may execute your ExternalInterface.call("multimedia_loadSettingsString")?

I validate ExternalInterface.available prior to each call...

Thank you in advance for your time and effort.

UVSAR
Expert
Registered: Oct 29 2008
Posts: 1357
There's a slight delay between Flash Player loading the SWF and Acrobat waking up its JavaScript engine, so if you make an EI call from the SWF as soon as it loads, you often find it falls on deaf ears. Unfortunately .available will always return true as the framework is registered before Flash Player opens an eyelid, so checking that won't help.

We tend to make a dummy call to Acrobat JS as part of the SWF's initial code - e.g. ExternalInterface.call("eval(1+1)") - and we loop a few times if there's a null return. That way we can give AcroJS time to get out of bed, but also the SWF can fail gracefully if the user's disabled it (in which case, .available will STILL be true, even though there's nothing listening).
Mugsy
Registered: Feb 23 2010
Posts: 3
I took the easy way out, but I thought I would report back with a solution.

Quick Sumary - I embedded a SWF file into a PDF and need ed to store some data.

A great reference is : http://blogs.adobe.com/pdfdevjunkie/...wf_conten.php


1. Acrobat 9 and later allows embeded SWF files and runs them natively - so no need for a Flash player.

2. For security purposes it allow SWF to communicate with Acrobat via ExternalInterface calls such as :

ExternalInterface.call("multimedia_saveSettingsStr ing", myString);
ExternalInterface.call("multimedia_loadSettingsStr ing");

The problem though is that there is no way for you to know WHEN Acrobat is ready to respond to such calls. Although Acrobat knows if there is an embedded SWF file in it, it will not initialize communications and thus respond to ExternalInterface call until the Flash file is activated.

Lack of notification of Acrobat's readiness to respond forces us to uses "bad programming practices" like, introducing repeated requests and monotoring the response.

As a result, I too waited until I recieved the COMPLETE event from the stage and then activated atimer that would send ExternalInterface calls every second until a valid response was recieved...

Hopefully, someone at Adobe will add a READY event so that we can work more intelligently...
UVSAR
Expert
Registered: Oct 29 2008
Posts: 1357
There's no reason why you can't code in a "ready" event yourself, simply by getting AcroJS to call a function in your SWF via the rich media annotations runAS() method. That function can then kick-start the SWF, but as you'll need to timeout the code for cases where it's never called (AcroJS disabled, etc.) it's no slicker than the repeat-test method. The drawback is that you have to put JS in the PDF, whereas testing from the ActionScript end means the SWF can be dropped into any document in a single click.

Acrobat 9 and Reader 9 have an embedded instance of Flash Player - it's hobbled to stop some of the local object access but aside from that it's the same as the standalone Player, so adding special AS classes to the embedded version would not be a good idea (not least, debugging your code in the Flash/Flex IDE would need another extension).
ekschperte
Registered: Jun 12 2010
Posts: 29
Sorry, I think, I don't got the idea of a "ready" event and the "repeat-test method". What do I have to do to save the swf state persistently? My code is not working, even if I connect my "save"-function to a button click.
public function saveInput():void
{
var result:Object = ExternalInterface.call("multimedia_saveSettingsString", "foo");
}

-mx:Button label="save" click="saveInput()"/-

The result variable is always false... :-( All other EI-calls do work... but not that for saving the swf state! Strange.
UVSAR
Expert
Registered: Oct 29 2008
Posts: 1357
Without seeing your code it's difficult to say, but the simple answer is that it does work (i.e. mm_save does return "true" when it completes). You don't even need Acrobat JavaScript enabled, as the functions aren't in the API proper - they're special definitions that only exist within the ExternalInterface tunnel, which is why running them in the Acrobat console gives an error.

Can you upload your code somewhere and pass us a link?
ekschperte
Registered: Jun 12 2010
Posts: 29
Hi. Ok, I am working with iText (http://api.itextpdf.com/) to produce a PDF with an embed swf. I think, there should be the problem since the original code for the swf from http://blogs.adobe.com/pdfdevjunkie/2008/08/saving_the_state_of_swf_conten.php is not working for me when embedding the swf into the pdf with iText. The swf states are not saved...

Here is my code:
The mxml file: http://stevenbirr.bplaced.net/filemanager/SaveSettings.mxml
The resulting swf: http://stevenbirr.bplaced.net/filemanager/SaveSettings.swf
The java file to generate the pdf with iText: http://stevenbirr.bplaced.net/filemanager/SaveSettings.java
The resulting pdf: http://stevenbirr.bplaced.net/filemanager/pdf3d.pdf
ekschperte
Registered: Jun 12 2010
Posts: 29
Still noch found the solution for that problem. :-( Probably I need to change the security settings of my swf produced with Flash Builder 4, but I don't know how. It seems, that it is not possible to read and save the state of the embed swf with the built-in functions ExternalInterface.call("multimedia_saveSettingsString", "foo"); and ExternalInterface.call("multimedia_loadSettingsString");. When I use the the pdf file from http://blogs.adobe.com/pdfdevjunkie/2008/08/saving_the_state_of_swf_conten.php, I can do it with my Acrobat Reader 9.3, but not with the same mxml file compiled with Flash Builder...