Having a very similar challenge this morning.
has anyone stumbled upon a solution?
i.e. How to have a SWF (embedded in a PDF) load a form's textfield: "value" ?
Objectve: given
~ SWF is embedded in PDF
~ form fiel;d in PDF = "name1"
Coding task;
how to code the SWF so that it can use the PDF texfield while
embedded in the PDF.
Also, is this a push from PDF OR a pull from the SWF?
ideas;
loadVars
myFlashVars
event.value string
Many Thanks
Dale
You have a couple of options for passing data into the SWF, FlashVars are not one of them. The Flash Vars are static. They are passed into the SWF at the time it is started.
But the other options are better.
1. In the SWF actionscript: Use the "ExternalInterface" object to call a function in the PDF.
2. Add a callback to the SWF, again using the ExternalInterface object. Then JavaScript code in the PDF can call this fucntion in the SWF
both are great options. YOu can find more details here:
http://pdfdevjunkie.host.adobe.com/RMA3_RMA2RMA.shtml
And of course you should also read the AnnotRichMedia entry in the JavaScript Reference.
Thom Parker
The source for PDF Scripting Info
pdfscripting.com
The Acrobat JavaScript Reference, Use it Early and Often
Then most important JavaScript Development tool in Acrobat
The Console Window (Video tutorial)
The Console Window(article)
I appreciate you explaining the Flash Vars usage and how they function.
I had assumed they were dynamic.
I will use you suggestions and the pdfscripting.com site
as my guide.......
Thanks Thom
As a reference, I am using my legecy
CS3 Flash w/ Arcobat 8 Pro, scripting w/ AS2 & AS3
Can I assume this will be vaild with you solutions?
Many thanks.
Dale
Hi Thom
Admittedly a novice on the AS3 & Java script side of things,
I use your references and gave the coding an attempt...
When you have a moment, I could use your review and
some further direction.....
Thanks in advance for your responses and help.
Dale
~ ~ ~
Givens on the SWF side;
~movie is published as: pdf_test.swf
~dymanic text instance: pdf_input
??confirm tis SWF script belongs in an 'action' layer (i.e. frame 1...) ??
code (actionscript3)
// to set up my function within my SWF
function nametextinput("names1") {
}
// to make my function available to the PDF java script
var connection = ExternalInterface.addCallback("mypdfId", null, nametextinput);
~ ~ ~
Givens on PDF side;
~file is saved as: text1.pdf
~form input textfield: name1
code (java script)
// to send PDF's form text field to the embedded SWF
// RMA is on page two, first RMA... and only RMA
function sendtoswf()
{ rma = this.getAnnotsRichMedia(1)(0)
ExternalInterface.call("myPdfId", null, nametextinput)
};
You're almost there. But there are a few issues.
1. Arguments to a function definition cannot be quoted strings. They are basically variable names. So if you want to pass in a single text string, i.e. the value of a field on the PDF then you could define the function like this:
function nametextinput(cName) {
}
2. The "addCallback" fucntion has two input parameters The name that will be used to call the function, and the actual fucntion that will be called. And it does not have a return value.
This is the correct code:
ExternalInterface.addCallback("mypdfId", nametextinput);
3. On the PDF side the "getAnnotsRichMedia" function returns an array of RMA objects
So here's what the code should look like for calling the "mypdfId" function, assuming that there is only one RMA on the page
var rma = this.getAnnotsRichMedia(1)[0];
rma.callAS("mypdfId", this.getField("TextField").value);
Thats how its done.
Thom Parker
The source for PDF Scripting Info
pdfscripting.com
The Acrobat JavaScript Reference, Use it Early and Often
Then most important JavaScript Development tool in Acrobat
The Console Window (Video tutorial)
The Console Window(article)
Hi Thom
Well I gave it the ole College try......
and could not seem to get it to execute.
Should you have a moment, I could use some more
Schooling in where I have failed.
Thanks in advance for your patience and help.
Dale
~~~~
In the SWF, I tried putting the code (below) first in
the ""publish settings" using AS3, then
tried an "action frame" in a new layer.. both attempts failed
SWF code
function nametextinput(cName) {
}
ExternalInterface.addCallback("mypdftext", nametextinput);
~~~
In the PDF, I tried putting the code in first the 'text field properties', 'actions' tab
using 'Trigger' as Mouse Enter and 'Action' as "run a JavaScript.... then
used the "Validate" tab and tried the 'run a custom validation script'.....
PDF code
var rma = this.getAnnotsRichMedia(1)[0];
rma.callAS("mypdftext", this.getField("TextField").value);
other references;
CS3 Flash Pro
Acrobat 8 Pro
All combo's, herein, did not execute.
Thanks again!
Good catch Dave, thanks
Dale, When you are trying to learn something new its' a good idea to start off simple, and to have a way to check your work. For example, all of the previous code you've posted would have thrown exceptions. These exceptions are an important debugging tool. I 'd suggest becoming familiar with the Acrobat JavaScript Console. And to make things simple, place all of your code in a MouseUp event on a button. Remove all code from the events on the text field. As a matter of fact, start with a blank PDF that only contains the elements you need for this solution, a button, a text field, and the RMA.
That takes care of the Acrobat JavaScript side. Now you need a way to verify the Flash side. Build your test Flash project with a single button and a text field. Make sure you know how to update text in the text field. Then write the function that will be called from the external interface to place text in this field.
On another note, the "addCallback" function should be called in the "ApplicationComplete" event of the SWF so it is setup right after the SWF is ready to play
Thom Parker
The source for PDF Scripting Info
pdfscripting.com
The Acrobat JavaScript Reference, Use it Early and Often
Then most important JavaScript Development tool in Acrobat
The Console Window (Video tutorial)
The Console Window(article)
Hi Thom,
I trust your New Year is off to a creative start.
RE: Text Field pass into SWF
~
Below is an update and a request for "fine tuning" these codes;
~ I have upgraded to FLASH CS5 and ACROBAT X Pro
( I have not studied FLEX)
I spent some time studying the Acrobat JavaScript Reference, JavaScript Debugger and reversed
engineered the PDF in the link you provided;
http://pdfdevjunkie.host.adobe.com/RMA1_acrossTheBridge.shtmlhttp://
Still, I must be missing something; a variable or syntax, format..., software version...
When you have a chance, I again, could use your coaching on what
I have missed or haven't yet understood.
Thanks in advance for your continued patience...
here's my facts:
SWF side using FLASH CS5
ActionScript 3
1) inserted a dynamic text on the stage, with a single frame, with NO instance name, "classic", and embedded my fonts
2) create an action layer with the following code (using AS3);
function nametextinput(fname) {
}
ExternalInterface.addCallback("pdfname", nametextinput);
3) saved, then published the file pdfname.swf
~ ~
PDF side using Acrobat X Pro
Per your suggestion;
One page, a text field, a Button and the RMA pdfname.swf
1) inserted a Form, Text-Field and named it 'fname' (without the ' ' ) ... no coding anywhere with the Text Field Properties
2) Inserted a Button ~ within the Properties, under the Action Tab, a Mouse Up trigger was added with a Run JavaScript action
3) within this JavaScript Editor the following code was placed;
var rma = this.getAnnotsRichMedia(0)[0];
rma.callAS("pdfname", this.getField("fname").value);
4) saved PDF as basic_v1.pdf
Using the JavaScript Debugger, I continually receive errors.
I have attempted many adjustments, i.e. Brackets / Syntax / naking conventions to no avail.
When I reverse engineered the PDF example ( ref above) I noted that codes
differ slightly from your suggestions (CAPs, more Brackets, and an app.alert is check if the RMA is Active !?).
I attempted adjusting for that, but again, unsuccessfully.
So, again, I like'd to understand what I am missing as
much as I'd like to complete this objective.
When you have a chance, I would welcome you help.
Many thanks,
Dale
Fremont, CA
You're getting confused with what's a function name and what's the name of the document and there are some quotes missing - but you can basically forget all of that anyway. There's no need for anything to be added to the document JS. Instead, simply use the eval() method. Assuming your form field is called 'fname', in your SWF just run this one line of code:
fieldValue = ExternalInterface.call("eval","getField('fname').value");
Note the use of double and single quotes. You can use eval() to send anything which returns a single value, from the name of a variable to an entire function.
Hi Dave,
I used your suggestion by doing the following;
While in FLASH, used the single line of code you listed, paying special attention to the use of quotes.
Yes, the name of the PDF text field is (fname).
Within the PDF, I did not remove / adjust the JavaScript on the MouseUp Button.
~~~
Unfortunately, my attempt w/ this method did not
transfer the TextField data input into the SWF (RMA).
Clicking the SWF and or the Button (w/ JS) and combinations did not produce the result.
Troubleshooting included:
Editing the SWF once placed in the PDF (SWF properties): played with 'Launch' /Activation Settings, considered the use of the 'properties' SWF and Resource TABs, to no avail.......
When you have a chance, let me know what /where I may be failing at this attempt......it's a tougher learning curve than I had anticipated.
Thanks
Dale
Dale:
If you want the trigger for passing the PDF form field value to the text object in the SWF, your ActionScript code would look like this...
myText.text = ExternalInterface.call("eval","getField('fname').value");
If you want to trigger to be in the PDF file, the SWF will need to be running and then you need to call an exposed function and pass in your variable.
Start by adding a function in ActionScript that sets the valie of your text object, then add a function for creationComplete that adds a callback for that function. init() is my creationComplete function and I expose the same internal name to the external interface just to keep things clear.
private function init():void{
ExternalInterface.addCallback("fillText", fillText)
}
private function fillText(valueFromAcroField:String):void {
myText.text = valueFromAcroField;
}
Then use callAS to call the SFW function from Acrobat. Assuming your annotation is "RMA" that'd be...
RMA.callAS("fillText", getField('fname').value)
It's a lot of plumbing but it works.
J-
Joel,
Thanks for your response;
within the SWF... using AS3,
dynamic text field with no
instance name...
I have received this error : "1013: the private attribute maybe used only on class property definitions"
I have yet to dive into using / understanding the effective use of "Class".
Your guidance would be very appreciated....
Just for my notes, my SWF file was developed in FLASH CS5 and
was 'published; with the file name pdfname.swf .
What I want to understand is your reference "Assuming your annotation is RMA".
Using Acrobat X Pro,
I added my said SWF (pdfname.swf) file via Content / Multimedia / SWF
Is this SWF and your RMA reference one in the same?
I just want to make clear I am learning the right terminology.
Should the RMA be something other than my current "steps",
I would welcome any clarification.
Thanks in advance for your time.
D
You'll need a way to identify the particular tect field you want to change the "text" parameter of in the function that you call from Acrobat then you need to expose that function so that Acrobat can call it.
The examples at the URL below will show you how to call an ActionScript function from Acrobat.
The documentation at the URL below explains ExternalInterface. The docs refer to a browser but in this case the host is Acrobat or Reader.
J-
Hi Joel,
First I like to say I enjoyed your video on "AcrobatUsers.com" re: inserting QR codes.... this was very helpful
http://acrobatusers.com/tutorials/adding-rich-media-your-pdf-files-nov ember-2011
~~
Per your Mar 2, post, I was attempting the AS3 code within my SWF ( no coding within the PDF)
I tried to resolve the following errors without success. (i.e. brace inputs, changing quotes...)
I would appreciate your guidance.....
Thanks for your help.
Dale
Errors
1084 Syntax error: expecting identifier before "getField('fname').value".
1084 Syntax error: expecting rightparen before rightbrace.
Hi Joel,
I really appreciate your prompt response.
~~
I have manage to get myself quite confused...
Using your two options suggested on Post #26 above,
I read the first option as an AS3 to be within a/my SWF file.
And assumed there was no JavaScripting on the PDF side
(i.e pulling the PDF test field ('fname') into the SWF via AS3)
When you have a chance, I could use a thorough walk through...
Many thanks.....
Dale
Dale:
The Flash runtime inside Acrobat does not have direct access to anything in the PDF. In fact, it barely knows it running in Acrobat rather than a browser. All it know is that it's running in a host. So... for the SWF to get information from the PDF, you need to send the PDF some JavaScript that returns some value. You can then use that return value to do things in your SWF. How does that work.
Acrobat JavaScript, unlike ActionScript, has an "eval" function that will cause a string to be evaluated and executed as though it were code, we can take advantage of this inside Flash. If you were in Acrobat and you wanted to know the value of a field named "foo" then JavaScript would be...
myVal = this.getField("foo").value
... to get this information from inside a running SWF in Acrobat, you need to push the code into Acrobat through ExternalInterface and the return value will be your variable. We need to change the double quotes to single so we can nest them.
var fieldValue:String = ExternalInterface.call("eval","getField('foo').value");
Technically, there's no JavaScript in the PDF itself, this JavaSCript just runs in memory. If you're going to work withthis sort of thing you need a good understanding of both ActionScript AND Acrobat JavaScript.
Is that more.... or less clear?
J-
Hi Joel,
below is my AS3 attempt last evening;
// as if used in a Browser
varLoader: URLLoader = new URLLoader();
// noting the "fname" is the textfield name in Acrobat
loader.load(new URLRequest("fname"));
loader.addEventListner(Event.COMPLETE, onComplete);
function onComplete(event:Event):void
{
// 'myText' is the instance name of the dymanic textfield, with 'fname' the textfield with Acrobat
myText.text = ExternalInterface.call("eval","this.getfFeld('fname').value");
}
Note: no JavaScripts were performed in Acrobat
I look forward to your guidance.....
Dale
Joel,
Your explanation noted above was very clear,
both in context and what I need to study.
So, when I attempted to use only the code noted above ( with any other AS3, Braces {}...)
I keep getting syntax errors 1084 noted in my post#29 above...
Other notes.....
currently I have my dynamic text with an instance name of myText... is this proper?
Dale
Joel
for clarity
I meant to type "without any other AS3, Braces {}..."
I have fixed the Syntax error, while review the code, I noted "this. was added in a recent reply.
That seemed to address this challenge.
I am currently addressing an output error: TypeError: Error 2007: Parameter must be non-null.
at Flash.text::TextField/set text ()
at pdfname_fla::MainTimeline/ frame 1
While researching this, I would welcome your insight.....
as a reference, the SWF dynamic text field instance is named myText ( unsure if this is the/an issue)
Thanks again for your time......
D
UPDATE March 19, 2012 ~DS:
No Errors, but no Text Interface (between PDF & SWF)
With the Codes noted below, there are no AS3 "Output / Compiler errors"
and on the Acrobat side, JavaScript debugger did not report any errors.
With the SWF (RMA) loaded in the PDF... the two text fields are still not interfacing (PDF to SWF).
Please take a look at the retyped** Codes and notes posted below and
let me know how you would adjust.
SWF side:
Dynamic text instance: namehere
Button name: play_btn
file saved as: swf_to_pdf.swf
Code AS3
full retyped script as stated in SWF
/* "swfPdf" is used to 'call the function' (use this in the Acrobat PDF JavaScript)
'fillText' is the actual function seen below that will be called
'fname' referenced in fillText function(below), is the Acrobat textField name
*/
// Button set up
function clickHandler(event:MouseEnter):void
{
trace("Click!");
ExternalInterface.addCallback("swfPdf", fillText);
function fillText(fname):void
{
this.namehere.text = this.ExternalInterface.call("eval", "this.getField('fname').value");
}
}
// assign Listener
play_btn.addEventListener(MouseEvent.CLICK, clickHandler);
~ ~
PDF side
PDF has one page and only one RMA (0)[0]
Form Text field: fname
Button (name): play
file saved as: pdf_rma_test.pdf
OnMouse Up, the code within the Button reads as follows
(full, retyped JavaScript as stated in PDF);
var rma = this.getAnnotsRichMedia(0)[0];
rma.callAS("sfwPdf", getField('fname').value);
Notes and observations:
While no errors were thrown on either side, please consider the following;
AS3 side
Acrobat side
Other
Can this effort the communication ??
currently set as Enable When: the page containing the content is opened
Disable When: the page containing the content is closed
** is there away to cut & paste code within a Forum / Discussion?
Many thanks for your time and guidance.....
D~
Message was edited by: DaLe Zki on March 19, 2012....
Hi Thom,
As I am unsure if you are prompted with new / updated Discussion Posts, I would
welcome your feedback on my most recent coding for this project.
See Post #38
In sumamry, there are no errors on the SWF AS3 side nor the Acrobat Javascript side, and yet,
the to Text Fields are not interfacing.
Thanks in advance for any time you can spare.....
Dale
North America
Europe, Middle East and Africa
Asia Pacific