Forcing classes to compile in AS3

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:


Actionscript:
  1. import sprites.Ball
  2.  
  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.

Tags: ,

One Response to “Forcing classes to compile in AS3”

  1. Touch My Pixel Blog » Blog Archive » Workaround for AS2’s exclude.xml in AS3 Says:

    [...] Touch My Pixel Blog Games + Web « Forcing classes to compile in AS3 [...]

Leave a Reply