Prev | Current Page 617 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"


import flash.Lib;
import flash.MovieClip;
class Main
{
public static function main()
{
var mc = createMovieClip();
drawRect(mc, 0, 0, 200, 200);
var mc2 = createMovieClip(mc);
drawRect(mc, 140, 140, 50, 50);
mc._x = 110;
mc._rotation = 30; // in degrees
}
#if flash6
private static var nextid = 0;
#end
private static function createMovieClip(?parent : MovieClip) : MovieClip
{
if(parent == null)
parent = Lib.current;
#if flash6
// flash 6 does not have the method getNextHighestDepth()
// and the depth must be managed manually
var id = ++nextid;
#else true
var id = parent.getNextHighestDepth();
#end
return parent.createEmptyMovieClip(???mc_??? + id, id);
}
private static function drawRect(mc:MovieClip,x:Float,y:Float,w:Float,h:Float)
{
mc.lineStyle(1, 0x000000);
mc.moveTo(x, y);
mc.lineTo(x+w, y);
mc.lineTo(x+w, y+h);
mc.lineTo(x, y+h);
mc.lineTo(x, y);
}
}
To compile the preceding example and the other examples in this section that target Flash 6 to 8, use the
following command at the prompt/console:
> haxe -swf main8.


Pages:
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629