Tony Polinelli
Tarwin Stroh-Spijer

contact [at]

6/25 Easey Street
Collingwood, 3066
Vic, Australia

+61 3 8060 5321

Archive for May, 2008

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)

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.

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:

  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.

Friday, May 9th, 2008

when you use the "import package.Class; " or "import package.*; " in AS3 the class(s) is not forced to be imported. A class is only imported if you use it somewhere in your code.

The simplest way is to just type its name:

  1. import sprites.Ball
  3. public function init(){
  4.    Ball;
  5.    // Or for many at once
  6.    (Ball,Dirt,Kid,People);
  7. }

Just simply typing the class type somwhere in your application will force it to compile in. Why is this of any use you may ask?

We use it for level building in games, where you have a generic component as a placeholder used in flash to lay out content/levels. Your Ball class for instance, might then simply build itself using externally loaded assets, and attach itself to the stage. It may not need to be referenced anywhere in the application, but is still compiled in.

Monday, May 5th, 2008

Sometimes you want to be able to use a timeout or interval but, as they are tied to milliseconds, if the frame-rate of your movie goes down from what you expected - games is a good example - then you can run into trouble.

I recently had this problem with a game, that when the frame rate lowered, cyclic "emitters" (ie creating bubbles underwater) would not be synced with the expeted speed of the game.

The solution. A setInterval and setTimeout that you can set using milliseconds (or frames if you want) and will be called at the expected number of frames. The only caviet with this approach is that it needs to be inited with the stage object, both so it can get an ENTER_FRAME event and the current FPS.

Our Friends:

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