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:
import sprites.Ball public function init(){ Ball; // Or for many at once (Ball,Dirt,Kid,People); }
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.
This entry was posted on Friday, May 9th, 2008 at 11:47 am and is filed under Flash, Tips and Tricks. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
3 comments
-
May 9th, 2008 at 2:10 pm[...] Touch My Pixel Blog Games + Web « Forcing classes to compile in AS3 [...]
-
July 21st, 2009 at 7:23 amNice 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.
-
July 21st, 2009 at 9:54 amOh 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