Prev | Current Page 296 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"


To illustrate the inclusion of external libraries in Flash, a very simple class Drawer is defined in a new
project directory; the class purpose is to draw simple shapes (a rectangle and a poly - line) on the passed
movie clip (Flash 6 to 8) or sprite (Flash 9). It is important that the directory is different from the one of
the current project or there is the risk that the class is erroneously included in the source compilation
invalidating the examples. The class will be compiled in an swf file that will be included first in a static
way and after in a dynamic way.
// content of file Drawer.hx
import flash.Lib;
class Drawer
{
#if flash9
private var g : flash.display.Graphics;
public function new (mc : flash.display.Sprite)
{
g = mc.graphics;
}
#else flash
private var g : flash.MovieClip;
public function new (mc : flash.MovieClip)
{
g = mc;
}
#end
public function drawRect(x : Float, y : Float, w : Float, h : Float) : Void
{
g.lineStyle(2, 0x000000);
g.moveTo(x, y);
g.lineTo(x+w, y);
g.


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