Prev | Current Page 652 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

The problem is that the
MovieClip class cannot be directly instantiated and so do its derived classes.
To resolve the problem the MovieClip.attachMovie() method is used; it instantiates an object
from the library. The following example explains how to define a subclass MaskedClip from the base
MovieClip and instantiate it. The class adds a method setMaskSize() that creates a rectangular mask
for the current movie clip. A mask enables you to limit the visible area of an object. To define a mask on a
movie clip, a second one is created and associated to the first using the setMask() method. The shapes
drawn on the second movie clip are the visible area of the first.
(continued)
Chapter 12: Building Interactive Content with Flash
343
import flash.Lib;
import flash.MovieClip;
class Main
{
public static function main()
{
var mc = cast(Lib.current.attachMovie(???MaskedClip???, ???mymask???, 0), MaskedClip);
mc.setMaskSize(100, 100);
mc.beginFill(0x00ff00);
mc.moveTo(50, 50);
mc.lineTo(120, 50);
mc.


Pages:
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664