# Can't use animations with \input?

I have two different animations, made with TikZ and the animate package, that I want to include in a beamer presentation. When I had the code inside of my presentation's .tex file everything worked fine, then I tried to move the animation code into separate files and include them with \input, and it stops working.

Here's the especially weird thing: If I include only one of the animations and comment out the other, the code works. When I include both animations I get an error about

Missing \endgroup inserted


or

Something's wrong: perhaps a missing \item?


depending on whether I comment out the first or second \input. Any advice would be most appreciated. Below is a piece of the code just to give you an idea of what I'm doing (my complete preamble is included, just in case one of the other packages is what's causing issues).

\documentclass[xcolor=dvipsnames]{beamer}
\usepackage{mathrsfs}
\usepackage[absolute,overlay]{textpos}
\mode<presentation>
{
\usetheme{Singapore}
\usecolortheme{seahorse}
\setbeamercovered{transparent}
}
\usepackage{tikz}
\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
\usepackage{times}
\usepackage[T1]{fontenc}
\usepackage{color}
\usepackage{animate}  % Animations
\usepackage{fp}       % Fixed point calculations
\usepackage{ifthen}
\usepgflibrary{arrows}
\usetikzlibrary{decorations.markings, arrows, decorations.pathmorphing,
backgrounds, positioning, fit, shapes.geometric}

\newcounter{frame}
\setcounter{frame}{0}

\begin{document}
\begin{frame}[fragile]{Animation 1}
\begin{center}
\input{animations/anim1.tex}
\end{center}
\end{frame}

\begin{frame}[fragile]{Animation 2}
\begin{center}
\input{animations/anim2.tex}
\end{center}
\end{frame}
\end{document}


anim1.tex and anim2.tex are identical:

\begin{animateinline}[autoplay, loop, controls, poster=first]{15}
\whiledo{\theframe < 179}{
\begin{tikzpicture}
\draw (-3, -3) rectangle (3, 3);
\filldraw (\theframe : 2cm) circle (0.05cm);
\end{tikzpicture}

\stepcounter{frame}
\ifthenelse{\theframe < 179}{
\newframe
}{
\end{animateinline}
}
}


I'm very much a newbie with the animate package, so perhaps someone who's more knowledgeable will easily recognize what's wrong, but this is very frustrating right now.

Any help would be most appreciated.

-
Your preamble loads too many packages. It is recommended to remove the unnecessary packages from your current MWE. And please show your anim1.tex and anim2.tex. –  kiss my armpit Mar 31 '13 at 18:57
Added an example of anim1.tex and anim2.tex. –  cjohnson Mar 31 '13 at 19:38
Where is the frame counter defined? –  kiss my armpit Mar 31 '13 at 20:24
My mistake: I copied/pasted and in cutting out some irrelevant things from the preamble, got rid of frame. –  cjohnson Mar 31 '13 at 20:37
See my answer for the latest update. –  kiss my armpit Mar 31 '13 at 20:42

\documentclass{beamer}
\usepackage{tikz}
\usepackage{animate}
\usepackage{filecontents}

\begin{filecontents*}{anim1.tex}
\begin{animateinline}[autoplay, loop, controls, poster=first]{15}
\multiframe{181}{iAngle=0+1}{%
\begin{tikzpicture}
\draw (-3, -3) rectangle (3, 3);
\filldraw (\iAngle : 2cm) circle (0.05cm);
\end{tikzpicture}}
\end{animateinline}
\end{filecontents*}

\begin{filecontents*}{anim2.tex}
\begin{animateinline}[autoplay, loop, controls, poster=first]{15}
\multiframe{181}{iAngle=0+1}{%
\begin{tikzpicture}
\draw (-3, -3) rectangle (3, 3);
\filldraw (\iAngle : 2cm) circle (0.05cm);
\end{tikzpicture}}
\end{animateinline}
\end{filecontents*}

\begin{document}
\begin{frame}[fragile]{Animation 1}
\begin{center}
\input{anim1.tex}
\end{center}
\end{frame}

\begin{frame}[fragile]{Animation 2}
\begin{center}
\input{anim2.tex}
\end{center}
\end{frame}
\end{document}

-
If you borrow code from an answer in the site, you should mention the source. –  egreg Mar 31 '13 at 19:51
@egreg: Done. Thanks. –  kiss my armpit Mar 31 '13 at 19:55
I don't understand your answer. Are you claiming I should create a separate PDF for the animation and then include it with \animategraphics? Also, my question explicitly says that everything works fine with one \input (as is used in your example), but doesn't work once I use \input twice. –  cjohnson Mar 31 '13 at 20:00
Seems to work now. Thanks for your help! –  cjohnson Mar 31 '13 at 21:13