Prev | Current Page 619 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

You do not have to worry about depth levels because the
DisplayObjectContainer class that is an ancestor of the MovieClip class handles them internally;
this class also contains methods to swap and reposition the elements in the stack.
import flash.Lib;
import flash.display.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 = 105;
mc.rotation = 30; // in degrees
}
private static function createMovieClip(?parent : MovieClip) : MovieClip
{
if(parent == null)
parent = Lib.current;
var mc = new MovieClip();
parent.addChild(mc);
return mc;
}
private static function drawRect(mc:MovieClip,x:Float,y:Float,w:Float,h:Float)
{
var g = mc.graphics;
g.lineStyle(1, 0x000000);
g.drawRect(x, y, w, h);
}
}
Part II: Server Side, JavaScript, and Flash: Oh My!
322
The preceding example and the others in this section that target Flash 9 can be compiled using the
following command at the prompt/console:
> haxe -swf sample.


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