Connect .swf with media9

I found out that it is possible to call external javascript in an browser with my interactive .swf document using the ExternalInterface provided by Adobe. That means, that with e. g. button clicks I can trigger javascript commands (yes, I am aware of the media9 mediabuttons.) However, that doesn't seem to be possible in an LaTeX-generated .pdf, as one can only import the .swf document itself without the additional js-commands.

If that weren't the case, I could connect my .swf to media9 and therefore to other interactive graphics as well.

Is there a workaround or another possibility to achieve this?

EDIT: Let's add an example: Connect the hslider from this example to media9.

EDIT: Extend that example:

This is the slider in mxml:

<?xml version="1.0"?>
initialize="init();">

<mx:Script><![CDATA[

public function change():void {
}

]]></mx:Script>

<mx:HSlider id="aSlider" width="100%"
minimum="0.1" maximum="3" value="0.1"
dataTipPlacement="top"
snapInterval="0.01" tickInterval="0"
labels="[a=0.1,3]"
allowTrackClick="true"
liveDragging="true"
change="change();"/>
</mx:Application>


As you can see, it should, for the sake of simplicity, just set the frameNum of another animation my_anim (created with the animation package) to 10. However I can include this .swf with media9 without any problems, but there is no response to sliding.

What I am doing is probably nonsense, but my intention should now be clear.

• The players of the media9 package are controlled in exactly the same way as you describe, that is, through methods exposed to JavaScript via the ExternalInterface. Bi-directional communication is possible. Can you post a specific example? Otherwise, your question is too broad. – AlexG Oct 2 at 6:56
• It seems like you're exactly the right guy to answer this, see edit :D – Ultimate Trick Oct 2 at 9:20
• The swf in the linked example doesn't use ExternalInterface and cannot be controlled from outside. But, VPlayer.swf from media9 does. Its Flex source code is here: mirrors.ctan.org/macros/latex/contrib/media9/players/… . – AlexG Oct 2 at 9:34
• Yes, but how to include the js-part of the .swf? I mean, that's an additional file, right? – Ultimate Trick Oct 2 at 9:40
• Well, SWF may contain ActionScript not JavaScript, as far as I know. JavaScript embedded in the host document (PDF, HTML) is executed by the host application (Acrobat Reader, a Web Browser) and can call ActionScript functions of the SWF that are exposed via ExternalInterface. In the opposite direction, the SWF can call JS functions embedded in the host document. Do you have a minimal demonstration example of HTML with embedded SWF and JS, that you want to convert to PDF? – AlexG Oct 2 at 10:17

This example demonstrates SWF to PDF-JavaScript communication using Flash's ExternalInterface. The embedded Flash app slider.swf is a simple slider that changes the animation object's frameNum property.

\documentclass{article}

\usepackage{animate,media9}

\begin{document}
\begin{animateinline}[label=my_anim,step]{1}
\multiframe{10}{i=0+1}{
\fbox{\Huge\i}
}
\end{animateinline}

\includemedia[activate=pageopen,width=0.5\linewidth,height=12ex]{}{slider.swf}
\end{document}


Its source file slider.mxml

<?xml version="1.0"?>
<mx:Script><![CDATA[
public function change():void {
}
]]></mx:Script>

<mx:HSlider id="aSlider" width="100%"
minimum="0" maximum="9" value="0"
snapInterval="1" tickInterval="1"
labels="[0,9]"
allowTrackClick="true"
liveDragging="true"
change="change();"
/>
</mx:Application>


is compiled to SWF using Flex (flex.apache.org)

mxmlc -strict -warnings -compiler.as3 -static-link-runtime-shared-libraries -compiler.optimize -keep-generated-actionscript slider.mxml