Prev | Current Page 300 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

Flash 6 versions can be compiled in this way:
> haxe -swf index_f6.swf -swf-version 6 -swf-lib f6.swf -main Main
The external libraries must be copied in the same directory as the source code to be reachable by the
compiler, or the path in the switch statement must be changed to point the correct path.
To enjoy the strictly typed constraint of the compiler, it is possible to define an extern class for the
Drawer class.
extern class Drawer
{
#if flash9
public function new (mc : flash.display.Sprite) : Void;
#else flash
public function new (mc : flash.MovieClip) : Void;
#end
public function drawRect(x:Float, y:Float, w:Float, h:Float) : Void;
public function drawPoly(coords:Array < Array < Int > > ) : Void;
}
The class can now be used as if the class is defined directly in the host project; see how the previous
example can be simplified.
// content of file Main.hx
class Main
{
static function main()
{
var drawer = new Drawer(Lib.current);
draw(drawer);
}
(continued)
154
Part I: The Core Language
private static function draw(drawer : Drawer)
{
drawer.


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