| Register
Saturday, May 17, 2008   

Far Beyond Open Source Flash Development

Created By  Carlos Rovira, at  1/3/2006 - 10 comments.

Click to view this author's website.

Nowadays, Open Source Flash Development has become a reality, but things continue to move.

Projects have been evolving quickly in the past year regarding our recently born Open Source Flash World. The Eclipse based environment advocated in the first installment of this series of articles and baptized as FAME by Jesse Warden is now more capable than ever before.

Nowadays:

  • Flashout has been entirely deprecated in favor of the new ASDT features like The SWFViewer and The AS Logger (so we have lost the 'F' of 'FAMES' to become 'AMES').
  • We are using ANT Eclipse feature more and more along with as2ant tasks to build our SWFs.
  • In order to embed our art inside our SWF (clips, fonts, images,...) now we have SWFMill.
  • A myriad of open source projects have been born, mainly at the osflash.org site, which gives you powerful capabilities in your day by day development (look at ActionStep or Red5, for example...)
  • These are only a few of the important things that happened through 2005 but it's too much to cover in detail in a single article, for this reason I'd like to concentrate in a single point: the ANT tool.

ANT

It was six years ago while consulting at Vodafone Spain where I was introduced to a very useful and productive tool to help build our Java projects. It was of great help for me and my co-workers. That tool was Apache ANT. Since the ANT software came to the stage a lot of products in the market were integrating this Apache Open Source project due to its useful features. One of them was the Eclipse Platform that many of us use today to create our SWF experiences.

ANT is a build tool that uses an XML dialect to execute the tasks that you, the developer, are requesting. The nature of the tasks are very diverse, from copying files to some directory, generating files (SWFs, XMLs or even classes) on the fly or transferring files via ftp to your favorite remote server. These are only a few examples of ANT's Power.

Now that you are producing SWFs in a more standard way thanks to open source, maybe you'll want to invest some time looking through the ANT manual to discover some hidden gems that improves your development workflow. By the way, using ANT you'll always have full control over your project and will maintain it free of dependencies from other production environments and IDEs.

The following are some tips and tricks that may be handy in your flash open source development. If you have never used ANT for flash development until now, you can check the following tutorial for a great guide to get started.

I recommend that you open your Eclipse IDE to follow my explanation, and create or open any ANT build.xml. Note that properties and build files must be in the project's root folder

USE PROPERTIES FILES

Instead of declaring all your properties in your build file, make one external file to be able to reuse it in other projects. You could create an "ames.properties" file and reference it from your build XML file, using the following XML tag:

<property file="ames.properties"/>

The "ames.properties" file could have the vars you used to write in mostly all your build files like:

#AMES Home
ames=C:/AMES

#SWFMill
swfmill=${ames}/swfmill/swfmill.exe

#MTASC
mtasc=${ames}/mtasc/mtasc.exe

#AS2ANT (see the section USE AS2ANT TASKS below)
as2ant=${ames}/as2ant/src

...

USE ANT PREDEFINED VARS

In Eclipse and inside a build file and "project" tag, if you type the $ symbol you'll get code hinting with the variables that you can use inside your custom build file. The vars list is constructed with ANT's predefined vars and your custom vars.

For example, If you are working in a team, the ${user.home} var could be invaluable to declare where in your local disk your flash 8 classes are, because it will be translated to each user's home directory. The following could also be in your newly created "ames.properties":

#FLASH 8 CLASSES
Flash8Classes=${user.home}/local Configuration/
  Program Files/Macromedia/Flash 8/en/Configuration/Classes

Or you could customize some file names automatically according to your project's name in your build file:

<property name="mtasc_out_file" location="deploy/${ant.project.name}.swf"/>

USE AS2ANT TASKS

Although you could use MTASC or SWFMill with the default exec ANT task, a recommended best practice is to use as2ant 1.0 (now in beta). This package provides you with three new tasks specially designed to use with your favorite open source swf related software. The tasks are MTASC, SWFMILL and SWF. To install it and use it in your build file:

You could create the "as2ant_taskdefs.xml" file:

<project name="as2ant_taskdefs" basedir="."
  description="as2ant_taskdefs"/>
	
  <property file="asdt.properties" />
		
  <!-- Define the as2ant tasks -->
  <taskdef name="mtasc"
    classname="org.as2lib.ant.Mtasc"
	 classpath="${as2ant}"/>
  <taskdef name="swfmill"
    classname="org.as2lib.ant.Swfmill"
	 classpath="${as2ant}"/>
  <taskdef name="swf"
    classname="org.as2lib.ant.Swf"
	 classpath="${as2ant}"/>
</project>

and import it from your build file:

<import file="as2ant_taskdefs.xml"/>

For example, you can now use the new tasks for SWFMill SWF creation:

<swfmill swfmill="${swfmill}"
  src="${swfmill_xml_file}"
  dest="${swfmill_in_file}"/>

or with MTASC:

<mtasc mtasc="${mtasc}" 
  version="8" 
  frame="5" 
  classpath="${project.classes};
    ${animationpackage_classes};${remoting_classes}" 
  swf="${swfmill_in_file}" 
  out="${mtasc_out_file}" 
  main="true" src="${mainclass}"/>

Notice that swfmill and mtasc attributes in each task must be set to the location where you installed the corresponding distribution of those tools.

USE ANT MACRODEF TO BUILD YOUR MACROS

As you refine your build files you'll need to refactor some common tasks and pass some variables. You can accomplish this with macrodef task. In the following example I've created a macrodef called "createSWF":

  <macrodef name="createSWF">
    <attribute name="version" default="8"/>
    <sequential>
      <echo message="create SWF macro"/>
      <mtasc mtasc="${mtasc}" 
        version="@{version}"
        classpath="${project.classes}" 
        swf="${swfmill_in_file}" 
        out="${mtasc_out_file}" 
        main="true" 
        src="${mainclass}"/>
    </sequential>
  </macrodef>

You use the "createSWF" macrodef with the following sentence inside a target:

  <target name="SWF-with-mx">
    <echo message="Creating SWF with mx flag..."/>
    <createSWF version="7"/>
  </target>

As you notice I'm passing a "version" attribute to the macro for configuration purposes and using it with the @ symbol.

CREATE YOUR NEEDED FILES ON THE FLY

Another great use for ANT is the possibility to create files on the fly. You could use this feature to create a config file or even a Class file before MTASC compilation:

For example use the following to create a class file with build information in folder "com/carlosrovira/myProject":

  <!-- buildnumber tag generates a file with an
    autoincremental number(build.number) -->
  <buildnumber/>
		
  <!-- project version -->
  <property name="build.version" value="1.0"/>
		
  <tstamp>
    <format property="build.time"
	   pattern="M/yyyy" unit="month"/>
  </tstamp>
	    	
  <echo message="${ant.project.name}
    version: ${build.version}.
    Build number: ${build.number}.
    Build Time:${build.time}" />
		
  <echo file="${project.classes}/com/carlosrovira/
    myProject/BuildInformation.as"
    append="false">
// --- This file is created by an ANT build task
// --- (see the build.xml file for more info)
class com.carlosrovira.myProject.BuildInformation {
  public static var versionNumber:String = "${build.version}";
  public static var buildTime:String = "${build.time}";
  public static var buildNumber:Number = ${build.number};
	
  public static var copyright_str:String = "Copyright(c) 2006 Carlos Rovira.";
}
  </echo>

If you create files with ANT and you're using Eclipse I recommend that you configure the ANT Build dialog checking "Refresh resources Upon Completion" (in this way you could refresh the folder, or the project, etc...). Also check Eclipse-ANT specific task:
<eclipse.refreshLocal/>

CREATE A SHORCUT KEYS IN ECLIPSE

This is an Eclipse-ANT specific trick. This would allow you to have a shortcut for building your project.

Go to the menu bar through Window and select the Preferences dialog window. Inside General > Keys you'll see a View Tab. You could select the Run/Debug Category with the command "Run Ant Build" inside the Datagrid. You could add another key combination inside the "modify" tab (Alt+Shift+X+Q is a little cumbersome in my opinion). Maybe some combo keys like the ones in Flash Authoring Environment (CTRL+ENTER or SHIFT+F12) could be very useful, isn't it?.

CONCLUSION

I hope you learn and enjoy some of the ANT tricks I explained in this article and improve your art in building your SWF projects. In the future, I expect ASDT will have more and more automation and ANT integration to build your SWF related projects, but at the moment is recommended to have a good knowledge about the possibilities you now have in your hands.

Need Professional Help For Your ActionScript Project?
ActionScript.com Consulting Services provide top quality professional ActionScript consulting to businesses around the globe. If you have a professional project in need to world-class talent, tell us about your project by requesting a quote today.

Reader Comments

  1. Tangent  Replied:
    ( 1/4/2006 At 2:51 PM)

    I hope you can take a look at the emerging open-sourced FlashDevelop (FD) which is lighter-weight compared to FAMES/AMES. The best thing of is that you get all the components in one package instead of trying to download and install from all over places, and it is fast compared to Eclipse for its lightweight nature.

  2. Carlos Rovira  Replied:
    ( 1/5/2006 At 6:21 AM)

    Hello Tangent, I've heard about FD in osflash.org list and I know that is growing great! (I read a lot of good things from many people from the flash community). But for me is not the dream enviroment for many reasons. As (at work) we are a team, we need more functionalities and not a light-weight IDE. I was searching for CVS and ANT integration, a unique IDE for Flash-J2EE development, and other things more suited for team development and Eclipse is a standard in Big Enterprise development. I think that each IDE must be used for a target audience. FD would be great for most Flash Developers comming to open source and working alone and without the need of integration with other technologies or doing Flash Remoting stuff (through OpenAMF for example...) Maybe, this IDE will be a good topic for another kind of article that brings the goods for its target audience.

  3. Valentin Backofen  Replied:
    ( 1/14/2006 At 11:16 PM)

    Since a few days one of my machines has taken the ominous step to Linux only. It is now running of Ubuntu, and doing so quite nice if I might add, my first meet with Linux as OS is rather plesant. Now I want to set up a true OS Flash workstation. I am all set up but am having some troubles with setting the CoreClass folder and am hoping for some pointers. When I rightclick the Core Folder of my AS2 Project I am told that the Resolved location: <undefined path variable>.
    I have copied the Classes Folder from my Flash 8 copy on the Windows XP machine to my 'Home' folder in Ubuntu. So I guess my question is if you have a possible solution to this. I have found a suggestion to mount the windows Class folder, but I do not quite agree with that, I would much rather have Core Classes on contained within the Linux environment itself.

    Other then that, thanks a lot for these two articles! They have been pure insipiration to me...

  4. Carlos Rovira  Replied:
    ( 1/15/2006 At 7:22 PM)

    If you want a "true OS Flash workstation" you might point the core classes to the MTASC core classes folder. If not, the enviroment will not be "pure os", but a hybrid enviroment.

  5. Valentin Backofen  Replied:
    ( 1/17/2006 At 2:49 AM)

    I found those too. But now the linked folder is still unresolved. And the code hints are not working. Any ideas on how to solve this? Haven't found anything on the ubuntuforums. The resolved location of the linked core folder is still "<undefined path variable>" when I right click it and select it's properties.

    Merci!

  6. Sandeep Datta  Replied:
    ( 1/17/2006 At 8:32 AM)

    First of all please accept my hearty congratulations on such a unique and wonderful article.
    Could you please justify the use of MTASC in place of the JavaScript Engine used by macromedia itself (which in freely available too , see SpiderMonkey at http://www.mozilla.org/js/spidermonkey/)

  7. Adam Bowman  Replied:
    ( 2/4/2006 At 4:13 PM)

    I was able to fix the <undefined path variable> error for the location of the core classes in Linux by editing the .project xml file. In the linked resources section, change the location from "core" to the actual path of the core classes.

  8. Adam Bowman  Replied:
    ( 2/5/2006 At 12:51 AM)

    I forgot to mention in my last post that after modifying the .project file you have to delete the project (without deleting the files) and then import the project back into your workspace.

  9. Adam Pasztory  Replied:
    ( 2/5/2006 At 8:35 AM)

    Hi Carolos. I loved your article last year was great -- It's what got me started with OS Flash. But I'm sorry to say that I can't make head or tail of this article. It seems to be just an arbitrary list of Things To Do With Ant. At the moment I don't have a great need to write macros, or generate AS files on the fly. Perhaps if you gave more of an overview of your ideal workflow, with examples, it might help me.

    Also, you say "Flashout has been entirely deprecated in favor of the new ASDT features like The SWFViewer and The AS Logger". I'm not familiar with these features at all. Are they in the current version of ASDT? Can you provide some more clarification, or links to tutorials/articles about how to use them? I'm still using Flashout, and I'm become quite fond of it, but I'm open to better ways. (I even tried FDT, but I felt their SWF viewer was *inferior* to Flashout.)

    Sorry for the negative comments, but I could use some more guidance.

  10. Todd Hivnor  Replied:
    ( 2/10/2006 At 10:38 PM)

    I'm still using Flashout, personally. What I like is that the compiler links back to the sourcecode. So if I have a compile error, I can just click and go to the offending code.

    I tried using the as2ant task, but it took more clicks to get stuff done, and didn't link back to the sourcecode when compile errors were found.

    So, I guess I don't see why as2ant is better than Flashout.

    Also, I had better luck invoking mtasc.exe with a direct <exec> task, as opposed to using as2ant. as2ant seems to require that your main class be in the root directory ... it can't be in a package. If you put your main class in a package, as2ant keeps adding that package directly to the classpath. So, I would rank the mtasc.exe invokers like this:

    1) Flashout (best because you can click from a compile error right to the offending sourcecode)
    2) Raw <exec> ant task (flexible)
    3) as2ant (worst because it forces main class into root package)

    Last, I use the ASDT logger, not the Flashout logger. Again, I like the way the ASDT logger let me click the log message and jump into the sourcecode.

Login to post your comments. If you do not have an account with us please Register.
Copyright 2005 by ActionScript, Inc.   |  Privacy Statement  |  Terms Of Use  |  ActionScript Client Extranet