Tony Polinelli
Tarwin Stroh-Spijer

contact [at]
touchmypixel.com

6/25 Easey Street
Collingwood, 3066
Vic, Australia

+61 3 8060 5321

Posts Tagged ‘Libraries’

Friday, May 9th, 2008

When creating external libraries, you often want the contents to have have a base class from your application. When you do this however, the whole application will often be compiled into your library due to its imports. This means two issues arise:

1/ You have a whole lot of duplicate code comipiled into your libraries, which will not be used (as when the lib is loaded any classes of the same name will not override the existing ones)

2/ It takes a bloody long time to compile your library (when it should be fast)

Solution:
The best way we have found to get around this is to create a empty classes, which work similar to intrinsics (but are totally empty -no functions, vars or imports), to replicate the base class.

Eg.
If in your application you have a class for example: 'sprites.enemies.Monster'
In your lib you will want to create an asset with identifier: 'Lib_Monster' and base class 'sprites.enemies.Monster'. Normally this would compile in the full Monster class and all its dependencies.

If you set up your lib.swf in a seperate folder to the application then create another class, lets call it a placeholder class, 'sprites.enemies.Monster' and just have it empty eg:

Actionscript:
  1. package sprites.enemies
  2. {
  3.     import flash.display.MovieClip;
  4.     public class Monster extends MovieClip{
  5.         public function Monster{}
  6.     }
  7. }

When it compiles the Lib_Monster will have the correct baseclass, but it will not include any code.

The trick is that, when the lib is loaded into your application the class 'sprites.enemies.Monster' will conflict. The application should have its own compiled version (the one with functionality) and when the lib loads in, it will ditch its version (the empty one) and adopt the existing (correct) version.

It only takes a few seconds to create the placeholder class for the library reference.

If you want to have the lib.fla in the same folder as the application, then you can even set up a different classpath for the lib. To do this go tot the publish settings and add a new classpath (eg. ./intrinsics). This path will be checked first for your placeholder class.

If for some crazzzy reason your classes arn't used (and so compiled) in the application (if you reference them with weak references), you will need to force them to be compiled in like this.

Our Friends:

Powered by haXe / poko cms | Copyright 2008-09 TouchMyPixel