There are multiple components of the engine that are compiled separately:
- the engine core:
- external elements:
- plugins: e.g.
- the preloader:
To compile a projector file (.exe / .app), see the tutorial "Building a projector".
How to compile
It is recommended components are compiled using the
mxmlc compiler which is part of the free Adobe Flex 3 SDK. An Apache Ant build file (
build.xml) can be found at the root level of each tag and the trunk itself. Once you have Ant up and running, you can just run it and it will compile everything in one go (except for the preloader, which has to be compiled using the Flash IDE, as it's a FLA file - reason is that vector graphics are used and it's much easier like this).
Adobe Flex SDK
First get the Adobe Flex SDK containing mxmlc. It must be version 3, version 4 does not work (yet).
Unpack where you like. Unpack to
C:/Program Files (x86)/Adobe/Flex 3 SDK. If your name of the folder is different, you must adjust the path in the
ant/build.properties file (property flex3dir) in the megazine SVN download package accordingly: in
ant/build.properties you'll see one line beginning with
FLEX_HOME, adjust the Flex SDK path right to the
= sign accordingly to where you extracted the SDK.
Then get Apache Ant.
Windows users: you might have to add the
bin folder of Java to the
PATH environment variable. Have a google at how to set environment variables in Windows if you need help for that.
Extract Ant wherever you like and add Ant's
bin folder to your
PATH environment variable. Also create a environment variable named
ANT_HOME and point it to the main folder (the one containing the
bin folder and the other stuff).
Now, open a command prompt, and change the directory to where you checked out the SVN tag or trunk. It contains a file named
ant, then press return to build everything.
Alternatively you can build specific parts only. Have a look at the
ant/build.plugins.xml files to find out the names of the targets. They follow a common pattern though:
To just build the NavigationBar plugin, for example, enter
ant build.plugin.NavigationBar and press enter.
publish target, to wrap things up, i.e. copy the compiled SWFs together with the other files necessary, such as localization and GUI file (from the
assets folder) together into the
publish folder. To do this, enter
ant publish to also compile beforehand,
ant publish.nocompile to skip compilation if you already did that anyway.
The resulting SWFs are put into the
OutOfMemoryError: PermGen space
When building everything in one go (which you'll do when just running
ant or using the build or publish targets), you'll most likely run into this error. To work around it you'll have to increase the maximum allowed memory used by ant and it's tasks.
- Setting this in Eclipse
- When using the ANT_OPTS environment variable, use
-Xms768m -Xmx1024m -XX:MaxPermSize=512m
- on Windows, you also can add
set ANT_OPTS=-Xms768m -Xmx1024m -XX:MaxPermSize=512mas first line into the apache_ant/bin/ant.bat file.
- Note: Not sure what the minimum required memory is, but this works, so I didn't bother testing anything lower.
If increasing memory falls short, you can always instruct mxmlc to fork into a new VM during compilation. Please see the Apache Ant Java Task documentation for an explanation of the fork attribute (the mxmlc task extends the Java task). Basically, fork causes a new VM to be created for each mxmlc invocation. Without fork, they all run in the same VM.
Compiling in Adobe FlashBuilder 4
- Create a new "ActionScript project" and choose the folder with the existing MegaZine3 source code files
MainFat.asas Main application file in the creation dialog
- After the project has been created open the project properties. Select "ActionScript Build Path", then the tab "Library path" and click the "ADD SWC Folder" button. Choose the folder
\liband click OK.
- Only necessary, when you still have external files to be loaded: Still in the project property window select "ActionScript Compiler" on the left panel. On "Additional compiler arguments" add the compiler option
-use-network=false. Otherwise the swf won't be able to load external files after it has been compiled.
- If you don't want to generate the HTML code (just the plain swf), uncheck "Generate HTML wrapper file".
- Close the project property window.
- Place your
mz3-configand assets in
- Now you have to generate the
\src\mightypirates\megazine\Assets.asfile which is responsible for including all external files within one swf later. This can easily be done by calling
python tools\make_assets.pyfrom command line (you may have to install Python first and add Python to your path variable). Be sure to navigate to the tools-subdirectory first. Otherwise the Python-script won't find the assets-folder.
- Before running the make_assets.py open it in an editor and make some adjustments. Around line 20 in the exclude array you can add or remove the subdirectories you want to have included in your compiled swf. For example, I have my pages as swf-files in a folder
pagesand didn't want them to be included, so I added "pages" and removed "megazine.mz3" which I wanted to be included in the swf.
- If you want to include the
megazine.mz3file you have to tell flash what kind of mime type it is. To do so, look for the statement
if e[e.rfind(".")+1:] in ["asul", "xml", "txt"]around line 44 and add "mz3":
["asul", "xml", "txt", "mz3"]. Run
python make_assts.pyfrom the shell. If everything went ok it should exit without any further message.
- Go back to Flash Builder and hit "Export Release build" in the toolbar or from the "project" menu item.
- Hit "Finish" in the upcoming dialog and you're ready. The fat swf is now in the directory
- If you want to go further into debugging you can of course also hit the debug-button. The compiled client should start automatically and is located in /bin-debug.
- If you have external files don't forget they have to be in the /bin-release resp. /bin-debug folders as well.