Tony Polinelli
Tarwin Stroh-Spijer

contact [at]
touchmypixel.com

6/25 Easey Street
Collingwood, 3066
Vic, Australia

+61 3 8060 5321

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: ,

3 comments


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


  2. Nice tip Tony! I was using Array before, like var compile:Array = [Ball,Dirt,Kid,People]; Didn't know you can just do it as you've shown. Btw. Man, your blog is amazing! Just found it today. I occasionally write Flash games as well. Thanks for sharing.


  3. Oh yeah, an array would make sense too. I dont know what this way is called & not sure if it is bad programming practice (just a compiler irregularity). It works in AS3, not in haxe tho. I have seen other people do it before however.
    I guess you could write the classes in an array too (sqare brackets):
    [Ball,Dirt,Kid,People];
    or just in a block (curly with semicolons):
    {Ball;Dirt;Kid;People;}
    cheers

 

Leave a Reply

Our Friends:

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