GhostWire Studios - Flash/Flex UI Components Development And Consulting Services
Quality User Interface Controls For Flash Application DevelopmentAspireUI Components

Jul 24 2009

Compiling Module SWFs Using FlashDevelop

Published by sunny at 7:28 am under Aspire UI,Flash,Tips

Breaking a large application down into modules allows the application to be loaded in more manageable chunks. A “module” is simply a term borrowed from Flex to refer to a child SWF that is loaded into a main (host) SWF – in our context, a “module” is just like any other SWF. But, if built correctly, it should be a “stripped down” SWF – it will not contain classes that already exist in the host SWF that it is going to be loaded into. This usually means that modules cannot run standalone (which is the desired outcome in most cases, considering that the modules are intended to be loaded into the main application).

When using FlashDevelop, building a Project (pressing F8 or CTRL-ENTER) compiles a single SWF using the AS class file that has been flagged as “Always Compile”. If you are building an application that consists of a host SWF and multiple module SWFs, FlashDevelop does not automate the job for you.


Use Multiple Projects
One way to build modules in FlashDevelop is to set up a different Project for each module, with each Project using the same assets but different build configurations (the module class in each Project is flagged as “Always Compile”). The Project for a module class would be set up such that duplicate classes are excluded (via compiler options). However, this can get troublesome and difficult to manage/maintain.


Use Quick Build
What you can do is stick to a single Project – when building the Project, the resulting SWF will be the main (host) SWF. Modules are built using the Quick Build command, accessed via the menu -> Tools -> Flash Tools -> Build Current File (CTRL-F8). This compiles the currently open class file, so you need to open the module class you want to compile and then press CTRL-F8.

The Quick Build command ignores your Project settings, so in order for this to work, you need to insert build options into each module class file. At the top of each module class, insert the following:

/**
* @mxmlc -o=bin/ClassName.swf -external-library-path=AspireUIStandard.swc
*/

The above is only an example, you can also specify other MXMLC options (optimize, default-size, etc.). In the above example, we exclude the classes in the AspireUIStandard.swc from being compiled into the module SWF. If you are using other libraries that are going to exist in the host SWF, remember to exclude them too.

To make testing easy, you can do the following:

/**
* @mxmlc -o=bin/ClassName.swf -l=AspireUIStandard.swc
* //@mxmlc -o=bin/ClassName.swf -external-library-path=AspireUIStandard.swc
*/

-l is alias for -compiler.library-path
Use that when you want to compile the module for testing standalone.


“exclude.xml”
Instead of using the -external-library-path option, you can also use an “exclude.xml” file and the -load-externs option.

Generate an “exclude.xml” from the main Project – in the project settings, compiler options, under “Additional Compiler Options”, add the following:

-link-report exclude.xml

Now build your project (CTRL-ENTER). Verify that the “exclude.xml” is generated and is in the root folder of your Project.

With the “exclude.xml” file generated, you can now use the -load-externs directive for your modules:

/**
* //@mxmlc -o=bin/ClassName.swf -l=AspireUIStandard.swc
* @mxmlc -o=bin/ClassName.swf -load-externs=exclude.xml
*/

This is recommended if the host SWF may not include all the classes in the libraries the modules are using.


uiSWF
Once you have created the module SWFs, you can have your host SWF load them using the uiSWF component (Aspire UI Standard Edition v1.2+). This control is a subclass of uiPane, making it suitable to be plugged in as the content of a uiScrollPane instance (in which case the module should not implement its own wrapper scrollers).

pixelstats trackingpixel
Share or Bookmark This Post:
  • StumbleUpon
  • email
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Live
  • Yahoo! Buzz
  • Netvibes
  • NewsVine
  • Reddit
  • Slashdot
  • Technorati
  • BlinkList
  • Mixx
  • Diigo
  • Faves
  • Suggest to Techmeme via Twitter
  • Twitter

Other Posts You Might Enjoy:

       

2 responses so far

2 Responses to “Compiling Module SWFs Using FlashDevelop”

  1. Fruitloopon 25 Jul 2009 at 11:08 am

    Thanks a lot for these blog tutorials, the posts you have made so far have helped me understanding flash and flashdevelop a lot better. Keep up the good work.

    -F

  2. Julianaon 07 Oct 2009 at 8:40 pm

    Thank you a lot!! I was this close to getting completely mad, because I couldn’t find a way to compile my swf modules. Actually, Flash Develop documentation on compiling is quite poor. Thanks a lot!

Comments RSS

Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word