Draknek's Deprecated Devloghttps://blogs.warwick.ac.uk/ahazelden
Archive of Alan Hazelden's programming blog, mostly about game development in Flash and C++ (ah, those were the days...)en-GB(C) 2018https://blogs.law.harvard.edu/tech/rssWarwick Blogs, University of Warwick, https://blogs.warwick.ac.uk120AS3 Flash dev in Linux byhttps://blogs.warwick.ac.uk/ahazelden/entry/as3_flash_dev/
<p>It is possible to create Flash applications from Linux using only free tools. It&rsquo;s also easy!</p>
<h4>Downloading the Flex <span class="caps">SDK</span></h4>
<p>The Flex <span class="caps">SDK</span> contains the compiler you&rsquo;ll be using. Flex is also the name of Adobe&rsquo;s Flash-based UI library but you do not need to use any Flex components to use the Flex compiler.</p>
<p>You can find it easily by searching for &ldquo;flex sdk&rdquo;. At the time of writing the most recent version can be found here: <a href="http://www.adobe.com/devnet/flex/flex-sdk-download.html">http://www.adobe.com/devnet/flex/flex-sdk-download.html</a>.</p>
<p>Older versions can currently be found here: <a href="http://sourceforge.net/adobe/flexsdk/wiki/Downloads/">http://sourceforge.net/adobe/flexsdk/wiki/Downloads/</a>. You want to get the &ldquo;Adobe Flex <span class="caps">SDK</span>&rdquo; rather than the &ldquo;Open Source Flex <span class="caps">SDK</span>&rdquo; because the Adobe one comes with the debug flashplayer program you&rsquo;ll be wanting to use for testing.</p>
<h4>Using the command-line compiler mxmlc</h4>
<p><span class="caps">MXML</span> is an <span class="caps">XML</span> schema for laying out UI components, but you don&rsquo;t need to (and don&rsquo;t want to) create any mxml files to use the compiler mxmlc.</p>
<p>The executable is in the Flex download in flex/bin/mxmlc. The minimal usecase looks like this:</p>
<pre><code>mxmlc Main.as</code></pre>
<p>Which creates a file Main.swf. A minimal Main.as might look like this:</p>
<pre><code>package
{
import flash.display.*;
[SWF(width = &quot;640&quot;, height = &quot;480&quot;)]
public class Main extends Sprite
{
public function Main ()
{
graphics.beginFill(0x000000);
graphics.drawCircle(320, 240, 100);
graphics.endFill();
}
}
}</code></pre>
<p>Generally you will want some give mxmlc some extra parameters though. I generally use these:</p>
<pre><code>mxmlc -optimize=true -output $OUTPUT -static-link-runtime-shared-libraries=true --target-player=10.0.0 -compiler.debug=true Main.as</code></pre>
<p><code>-optimize=true</code><br />
I&rsquo;ve heard this doesn&rsquo;t do a great job of optimising, but no reason not to include it really.</p>
<p><code>-output $OUTPUT</code><br />
Specifies the filename of the <span class="caps">SWF</span> to be generated.</p>
<p><code>-static-link-runtime-shared-libraries=true</code><br />
Starting with Flex 4 I get warnings if I don&rsquo;t include this parameter, and in some projects the application didn&rsquo;t run at all without it.</p>
<p><code>--target-player=10.0.0</code><br />
Target Flash Player 10 rather than the default Flash Player 9. Depending on the libraries you are using you can omit this.</p>
<p><code>-compiler.debug=true</code><br />
Generates debug information so you can get line numbers from stack traces. You probably want to disable this when compiling your final release.</p>
<p>You might also want to be aware of:</p>
<p><code>-compatibility-version=3.0.0</code><br />
Flex 4 has an incredibly annoying backwards incompatibility with Flex 3 where embedded fonts will silently fail and no text is rendered. This is one solution to that problem, the other is to add the parameter <code>embedAsCFF=&quot;false&quot;</code> to all font embeds in your code.</p>
<p><code>-frames.frame arbitraryframename ClassName</code><br />
This is used when you have a preloader. I won&rsquo;t go into the details of using a preloader here, but when I compile with a preloader I use <code>mxmlc [normal parameters] Preloader.as -frames.frame mainframe Main</code> which compiles Preloader.as and Main.as separately.</p>
<h4>Testing your <span class="caps">SWF</span> from the command line</h4>
<p>The Adobe Flex <span class="caps">SDK</span> (but not the open source Flex <span class="caps">SDK</span>) comes with a debug version of the Flash Player that will show error messages.</p>
<p>It is located in flex/runtimes/player/10/lnx/flashplayer.tar.gz</p>
<p>Note that there should be two versions included: 10.0 and 10.1. I have not been able to get the 10.1 player to output <code>trace</code> statements so I use the 10.0 player for debugging.</p>
<p>After you&rsquo;ve extracted it, you can test your application from the command line by running</p>
<pre><code>flashplayer Main.swf</code></pre>
<h4>Improving build times</h4>
<p>You might notice that compiling using mxmlc takes a very long time. This is because it has a lengthy startup time and doesn&rsquo;t keep anything in memory for future compilations.</p>
<p>There is another tool in the Flex package to help solve this problem called fcsh (the Flex compiler shell). Running <code>fcsh</code> will give you a shell, and typing mxmlc commands into that shell will cache some results for improved speed.</p>
<p>Unfortunately this is a horrible way to work: you don&rsquo;t want to use a specific shell for compiling, you just want a standalone command that can be run from bash, or from a makefile, or from wherever.</p>
<p>To solve this problem I wrote <a href="https://github.com/Draknek/fcsh-wrap">fcsh-wrap</a>. You use it as a drop-in replacement for <code>mxmlc</code> and it will use black magic to speed up your compile times.</p>
<p>There are also similar scripts available for emacs which I have not used, and hopefully any <span class="caps">AS3</span>-supporting <span class="caps">IDE</span> will have fcsh support built-in.</p>
<p><strong>Update:</strong> if for whatever reason you can&rsquo;t or don&rsquo;t want to use fcsh or fcsh-wrap, setting <code>-incremental=true</code> will give you some of the same performance benefits, although it will still be slightly slower.</p>
<h4>IDEs</h4>
<p>Speaking of which, what <span class="caps">AS3</span>-supporting IDEs are there for Linux?</p>
<p>Obviously you don&rsquo;t need an <span class="caps">IDE</span> because I&rsquo;ve been talking about the command-line compilation toolchain. You can use any text editor you like: personally I use <a href="http://www.sublimetext.com/">Sublime Text</a>, obviously the vi/emacs fans will choose to use vi and emacs.</p>
<p>For Sublime Text, you want to install the ActionScript 3 package through <a href="http://wbond.net/sublime_packages/package_control">this package manager</a>.</p>
<p>For gedit, you can get <span class="caps">AS3</span> syntax-highlighting support from <a href="https://github.com/julien/gedit_flex">here</a>.</p>
<p>In terms of actual IDEs, there seem to be two choices. They both have a pricetag attached, but I believe they are both free for students or for development of open source projects.</p>
<p><a href="http://www.jetbrains.com/idea/">IntelliJ <span class="caps">IDEA</span></a> is a Java-focused <span class="caps">IDE</span>, but the Ultimate edition comes with <span class="caps">AS3</span> support. Comes recommended by <a href="http://www.danielcassidy.me.uk/">Daniel Cassidy</a>.<br />
<a href="http://www.fdt.powerflasher.com/"><span class="caps">FDT</span></a> is a Flash-focused <span class="caps">IDE</span>. Looks worth checking out but I have no personal experience of it.<br />
<s><a href="http://www.adobe.com/products/flashbuilder/">FlashBuilder</a> is Adobe&rsquo;s product. It is essentially an Eclipse plugin.</s> <strong>Correction:</strong> <a href="http://labs.adobe.com/technologies/flex/flexbuilder_linux/">FlashBuilder is no longer available for Linux</a></p>
<h4>Useful <span class="caps">AS3</span> libraries</h4>
<p>This isn&rsquo;t Linux-specific of course, but I think it&rsquo;s relevant and useful to mention these here.</p>
<p>I was going to go into detail about why these are useful, but for the purposes of saving time I will just give you a list:</p>
<p><strong>Game frameworks:</strong><br />
<a href="http://flashpunk.net/">FlashPunk</a> (Use this one! Also use <a href="https://github.com/Draknek/FlashPunk">my branch</a>, it generally has a few more bugfixes and features than the official version.)<br />
<a href="http://flixel.org/">Flixel</a><br />
<a href="http://pushbuttonengine.com/">PushButtonEngine</a></p>
<p><strong>Physics:</strong><br />
<a href="http://box2dflash.sourceforge.net/">Box2D</a><br />
<a href="http://code.google.com/p/nape/">Nape</a></p>
<p><strong>Tweening:</strong><br />
<a href="http://www.greensock.com/tweenlite/">TweenLite</a></p>
<p><strong>Sound effects:</strong><br />
<a href="http://code.google.com/p/as3sfxr/">as3sfxr</a></p>
<p><strong>Misc. utility functions:</strong><br />
<a href="https://github.com/mikechambers/as3corelib">as3corelib</a></p>
<p><strong>Statistic logging:</strong><br />
<a href="http://playtomic.com/">Playtomic</a></p>
<h4>Embedding your Flash application in a webpage</h4>
<p>Again not Linux-specific but someone mentioned that this would be useful information to include.</p>
<p>I tried to embed the cross-browser <span class="caps">SWF</span> embed code into this post but it screwed up. Have a look at the <a href="http://code.google.com/p/swfobject/wiki/documentation">SWFObject documentation</a> (the &ldquo;static publishing&rdquo; section): you only really need step 1. Doing steps 2 &amp; 3 as well will let you detect whether the user has the right version of Flash installed.</p>
<p>Note that the <span class="caps">SWF</span> is embedded twice (for different browsers) so if you change its filename or its size, you need to change that in two places.</p>
<h4>And that&rsquo;s it!</h4>
<p>I think that&rsquo;s everything that you&rsquo;ll find useful. I&rsquo;ve been making Flash games in Linux for over a year and a half now and I&rsquo;m really happy with the tools available. Hopefully you will be too!</p>
<p>If anything here is unclear or you&rsquo;re having trouble getting it set up, leave a comment below or <a href="http://twitter.com/draknek">send me a message on Twitter</a>.</p>As3FlashGamesProgrammingFri, 21 Jan 2011 17:54:42 GMThttps://blogs.warwick.ac.uk/ahazelden/entry/as3_flash_dev/#comments094d735829a72d04012d95bf779416fe8