NOTE : This information is very old and only relevant if you are using ASDT 0.0.8build5. If you are using ASDT 0.0.9 then please head over to the ASDT Wiki for more recent information.
This is a quick tutorial to get you up and running with the ASDT Logger. If you need more detailed instructions about installing any particular component and getting it setup please head over to the tutorials page.
Getting started with ASDT and ASDT Logger
I'll assume you have downloaded, installed and configured the following :
So start Eclipse and create a new ActionScript2 Project. Im going to call it MyRecordShop (i do aim to write some more of these and will use this project as a basis)
Then create an AS2 Class in the src folder : MyRecordShop
And finally create an ant build file : build.xml (just make a normal file and call it build.xml)
Now, the last piece in the installation puzzle is some handy tasks for ant.
You need to download the ant tasks created by Simon Wacker
See the blog entry for AS2Ant Beta here
Or go straight to the download
then unzip and copy the folder somewhere useful, Im using D:\Work\Dev\Flash\Tools\as2ant
Now we'll use this ant build file
<project name="MyRecordShop" default="compile" basedir="."> <!-- Declares references to needed directories. --> <property name="src.dir" location="src"/> <property name="build.dir" location="build"/> <property name="main.class" location="src\MyRecordShop.as"/> <!-- Properties for the output movie --> <property name="width" value="500"/> <property name="height" value="500"/> <property name="framerate" value="31"/> <property name="bgcolor" value="FFFFFF"/> <!-- Define the MTASC ant task --> <taskdef name="mtasc" classname="org.as2lib.ant.Mtasc" classpath="D:\Work\Dev\Flash\Tools\as2ant\src"/> <!-- Target that uses the MTASC Ant Task. --> <target name="compile" description="builds sample swf"> <mtasc src="${main.class}" classpath="${src.dir}" swf="${build.dir}/${ant.project.name}.swf" main="true" header="${width}:${height}:${framerate}:${bgcolor}"/> </target> </project>
you can copy this into build.xml. Edit the MTASC taskdef tag so that the classpath contains the path you unzipped AS2Ant to, and save the file.
So, what this build file says is that we have a project called 'MyRecordShop' and the default action (aka target) is to 'compile'
The property declarations say where we are keeping our files, 'src' for our source code and 'build' for our output swf.
Looks like we should create the output directory (later we'll add a target which will create the right structure for us, but for now lets do it by hand)
Add a folder to the project in eclipse and call it 'build'
Now our project should look like this (except you probably wont see a .build file..i'll update the pic soon :)
Now, lets just run this build file and see what happens.
Right click on build.xml and choose Run As → Ant Build.
Heres my output :
''Buildfile: D:\Work\Projects\workspace\MyRecordShop\build.xml
compile:
[mtasc] Compiling 1 source file.
[mtasc] mtasc -swf D:\Work\Projects\workspace\MyRecordShop\build\MyRecordShop.swf -header 500:500:31:FFFFFF -cp D:\Work\Projects\workspace\MyRecordShop\src -main MyRecordShop.as
BUILD FAILED
D:\Work\Projects\workspace\MyRecordShop\build.xml:20: error running mtasc compiler
Total time: 297 milliseconds''
So it looks like ANT cant find MTASC. There are two ways to fix this problem.
The first is to add MTASC to your system path, the second is to use an attribute of the mtasc ant task to point it at the executable.
Lets take the second option.
The attribute is called 'mtasc'. So change the mtasc task definition to include the path to the mtasc executable. Mine looks like this :
<mtasc mtasc="D:\Work\Dev\Flash\Tools\mtasc.exe" src="${main.class}" classpath="${src.dir}" swf="${build.dir}/${ant.project.name}.swf" main="true" header="${width}:${height}:${framerate}:${bgcolor}"/>
Now lets try and run it again :
''Buildfile: D:\Work\Projects\flash-workspace\MyRecordShop\build.xml
compile:
[mtasc] Compiling 1 source file.
[mtasc] mtasc -swf D:\Work\Projects\flash-workspace\MyRecordShop\build\MyRecordShop.swf -header 500:500:31:FFFFFF -cp D:\Work\Projects\flash-workspace\MyRecordShop\src -main -cp D:\Work\Projects\flash-workspace\MyRecordShop\src MyRecordShop.as
[mtasc] Main entry point not found
BUILD FAILED
D:\Work\Projects\flash-workspace\MyRecordShop\build.xml:18: compile error
Total time: 781 milliseconds
mtasc runs but gives an error
'Main entry point not found'
So we need to add an entry point to the application, or in other words we need to write a function that will be called when the swf is played.
The standard for doing this with MTASC is a 'static main' function, much like in java and c.
Ok, so in MyRecordShop.as add the function code in the class definition, the complete class will look something like this
class MyRecordShop { public static function main():Void { } }
(and yes i like the BSD brace style, thanks :)
so save that, and lets build again.
SUCCESS!
If you right click the project in eclipse and select 'refresh' you should now find MyRecordShop.swf in the build folder.
Ok, it doesnt actually do anything yet, but we can now create our own swf's without going near the Flash IDE. Nice.
So, in the tradition of all programming tutorials lets get our program to say 'Hello World'.
Right, so in the flash IDE we would just write
trace(“Hello World”);
so, lets put that into our main function :
class MyRecordShop { public static function main():Void { trace("Hello World"); } }
and run the build. It should build ok, now if you run the MyRecordShop.swf nothing happens. Hmm, we have nowhere for our trace output to go.
So, how can we get some output from our application?
Well the short answer is 'Logging'.
Lately there has been an explosion of logging facilities for flash, and choosing a logger can be quite complicated. For now we'll focus on the logging facilities provided by ASDT.
First we can make a reference to the logging code in the project by creating a linked folder. To do this right click the project, New → Folder, then in the dialog that appears enter 'logger' as the folder name then click the 'Advanced' button. Now you will see an option to link to a folder in the file system. Check the box for that option then hit browse. Find your eclipse installation ($ECLIPSE_HOME) and head to $ECLIPSE_HOME/plugins/org.asdt.logger_0.0.8.build5/lib/flash_classes and hit ok.
This is actionscript code used for logging. Great, but how do we actually use it?
MTASC has a facility built in for re-directing trace statements, so we will setup our build to tell MTASC to redirect trace statements to our newly acquired logger.
I've added some information to the build file to tell it where our logging classes are and supplied the logging directory as an extra element in the classpath for MTASC.
<project name="MyRecordShop" default="compile" basedir="."> <!-- Declares references to needed directories. --> <property name="src.dir" location="src"/> <property name="main.class" location="src\MyRecordShop.as"/> <property name="build.dir" location="build"/> <property name="logger.dir" location="D:\Work\Dev\Apps\eclipse\plugins\org.asdt.logger_0.0.8.build5\lib\flash_classes"/> <!-- Properties for the output movie --> <property name="width" value="500"/> <property name="height" value="500"/> <property name="framerate" value="31"/> <property name="bgcolor" value="FFFFFF"/> <!-- Define the MTASC ant task --> <taskdef name="mtasc" classname="org.as2lib.ant.Mtasc" classpath="D:\Work\Dev\Flash\Tools\as2ant\src"/> <!-- Target that uses the MTASC Ant Task. --> <target name="compile" description="builds sample swf"> <mtasc mtasc="D:\Work\Dev\Flash\Tools\mtasc.exe" src="${main.class}" classpath="${src.dir}:${logger.dir}" swf="${build.dir}/${ant.project.name}.swf" main="true" header="${width}:${height}:${framerate}:${bgcolor}" trace="Log.addMessage"/> </target> </project>
Because MTASC is being invoked by ANT and doesnt know about linked folders, we have to point the logger.dir location to where the physical files are. You'll find them in $ECLIPSE_HOME\plugins\org.asdt.logger_VERSION\lib\flash_classes.
Also, you have to add the the logger folder to the classpaths in your project directory.
Ok, so one last modification to the source and we should be ready to roll, just change the trace to have an extra parameter :
class MyRecordShop { public static function main():Void { trace("Hello World", Log.INFO); } }
Now, run the build file again and it should compile fine. If not, check your path for 'logger.dir' is setup correctly.
note : to quickly run the build again you can click the green play button with the red suitcase in your eclipse toolbar.
Open up the AS Logger panel, and click the green play button (The logger uses an XML Socket, so this button starts it listening)
If you now refresh the swf you should see your log message appear in the AS Logger window.
please let me know if you have problems or have some comments. you can reach me at : flashdev at relivethefuture dot com
But, remember this is a WIKI and you are free to edit this page to improve and fix it.
thanks.