3

since months i cant find a way to change pictures by pressing a button in one field. With a text is is like:

\documentclass[a4paper]{article}
\usepackage{eforms}
\begin{insDLJS}[test]{test}{JavaScript}
function MakeArray(2){
    this.length=n
    return this
};
var text=new MakeArray(2);
text[0]='text111';
text[1]='text222';
this.getField("field").value=text[0];
\end{insDLJS}
%
\begin{document}
\textField[\BG{}\BC{}]{field}{80mm}{10mm}\\
\pushButton[\A{\JS{this.getField("field").value=text[1];}}]{myButton}{30mm}{15mm}\\
\pushButton[\A{\JS{this.getField("field").value=text[0];}}]{myButton}{30mm}{15mm}
\end{document}

But now i want to do the same with pictures in the same way that the picture changes by pressing the buttons. Is there something like: \pictureField[]{}{} or something simmilar?

EDIT
Thanks for the answer, but the problem is the media9 package. I have lubuntu tex-live fully updated with the most actual l3kernel (2014/...), so the other l3-packages. It still produces different errors, mostly: l3kernel too old, and some other funny errors. Found no way to get media9 operating. So i am sorry for asking again: Is there any way to do exactly this in your example but without the media9 package?

bummi
  • 105
Guest
  • 31
  • Your example doesn't work. To make it work, replace var text=new MakeArray(2); with var text=new Array(2); and delete the function def. – AlexG Dec 16 '14 at 10:23

1 Answers1

3

enter image description here

\documentclass{article}
\usepackage{animate,media9,graphicx,mwe}

\begin{document}

\begin{center}
\begin{animateinline}[nomouse,step,label=picfield]{0}
  \includegraphics{example-image-a}
\newframe
  \includegraphics{example-image-b}
\end{animateinline}

\mediabutton[jsaction={anim.picfield.frameNum=0;}]{\fbox{show (a)}}
\mediabutton[jsaction={anim.picfield.frameNum=1;}]{\fbox{show (b)}}
\end{center}

\end{document}

Using \PushButton from hyperref:

\documentclass{article}
\usepackage{animate,graphicx,mwe}
\usepackage{hyperref}

\begin{document}
\begin{Form}

\begin{center}
\begin{animateinline}[nomouse,step,label=picfield]{0}
  \includegraphics{example-image-a}
\newframe
  \includegraphics{example-image-b}
\end{animateinline}

\PushButton[onclick={anim.picfield.frameNum=0;}]{\strut show (a)}
\PushButton[onclick={anim.picfield.frameNum=1;}]{\strut show (b)}
\end{center}

\end{Form}
\end{document}
AlexG
  • 54,894
  • You use 'anim.picfield' to refer to the element. Is there an equivalent 'getField()' name? I have several images, to which I need to refer dynamically. – LBogaardt Dec 20 '16 at 15:41
  • 1
    @LBogaardt Are you using pkg animate, as in the example? You can have multiple \animategraphics/animateinline each with a unique label (I used picfield in the example) that can be addressed as anim["mylabel"] or anim.mylabel. You can even iterate over the anim[] array: for(i=0; i<anim.length; i++) {do sth with anim[i];}. – AlexG Dec 20 '16 at 15:57
  • @LBogaardt A completely different approach (without the need for JavaScript) is using PDF layers, via pkg ocgx2 for instance. – AlexG Dec 20 '16 at 16:00
  • Ah dude, awesome! Your first reply, using anim[i], is exactly what I needed. Thumbs up. – LBogaardt Dec 20 '16 at 16:39