Prev | Current Page 299 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"


Static Link
Linking a file statically requires less code and is less error prone than the dynamic option because the
external library is not loaded asynchronously but is embedded in the main file. The other advantage is
that the external library will be available at the same time of the classes declared in the main project.
153
Chapter 6: Organizing Your Code
This simplified approach permits the use of the same exact code on all of the flash versions:
// content of file Main.hx
import flash.Lib;
class Main
{
static function main()
{
var cl = Type.resolveClass(???Drawer???);
var drawer = Type.createInstance(cl, [Lib.current]);
draw(drawer);
}
private static function draw(drawer : Dynamic)
{
drawer.drawRect(20, 20, 80, 100);
drawer.drawPoly([[120, 10], [170, 100], [ 70, 100], [120, 10]]);
}
}
The code is very easy to use and implement. The most important thing is to not forget to add the switch
- swf - lib in the compiler command. The switch must be followed by the path of the file to import and it
can be repeated to import more than one file.


Pages:
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311