Today I’ve been looking for a way to print my code efficiently for my bachelor project. I use to copy paste everything but from now on this is a thing of the past. I decided to use LaTeX to format my code as it can pretty much do everything else.
I found a package that could help me print my code: listings
Now, there is no preset yet for ActionScript and apparently no Flex or Flash coder uses LaTeX frequently and is willing to share his preset. This forced me to create one myself and here is the result:
% Colors used by Flex Builder 3.
\definecolor{purple}{rgb}{0.65, 0.12, 0.82}
\definecolor{flexred}{rgb}{0.65, 0.01, 0.01}
\definecolor{flexgreen}{rgb}{0, 0.6, 0}
\definecolor{flexgray}{rgb}{0.25, 0.37, 0.75}
\definecolor{flexblue}{rgb}{0, 0.2, 1}
\definecolor{flexfunction}{rgb}{0.2, 0.6, 0.4}
\definecolor{flexvar}{rgb}{0.4, 0.6, 0.8}
% Define new language for listings.
\lstdefinelanguage{ActionScript} {
basicstyle=\ttfamily\scriptsize,
sensitive=true,
morecomment=[l][\color{flexgreen}\ttfamily]{//},
morecomment=[s][\color{flexgreen}\ttfamily]{/*}{*/},
morecomment=[s][\color{flexgray}\ttfamily]{/**}{*/},
morestring=[b]",
stringstyle=\color{flexred}\textbf,
commentstyle=\color{flexgreen},
showstringspaces=false,
numberstyle=\scriptsize,
numberblanklines=true,
showspaces=false,
breaklines=true,
showtabs=false,
emph =
{[1]
class, package, interface
},
emphstyle={[1]\color{purple}\textbf},
emph =
{[2]
internal, public, protected, private,
super, this, import, new, extends, implements,
void, true, false, as
},
emphstyle={[2]\color{flexblue}\textbf},
emph =
{[3]
function
},
emphstyle={[3]\color{flexfunction}\textbf},
emph =
{[4]
var
},
emphstyle={[4]\color{flexvar}\textbf}
}
All you have to do is load the listings package, set the language to ActionScript and insert your source files. Here is an example:
% Load the listings package.
\usepackage{listings}
% Set the preset of listings to ActionScript, defined above.
\lstset{language=ActionScript}
% Use this command to insert source file
\lstinputlisting{path/to/file.as}
% Use this command to format code
\begin{lstlisting}
ActionScript Code
\end{lstlisting}
This preset can be used to format ActionScript files and mxml files, although the latter is not fully supported, just the ActionScript between the <mx:Script> tags. If somebody has some additional code to support mxml, please let me know. I didn’t add this feature because I tend to avoid using mxml files.
Enjoy!

Hello,
Like you, I’m a student writing a Flex app as my final project, and I have to document it using LaTeX… this is just what I was looking for, thanks a lot!