Chapter 12: Building Interactive Content with Flash
329
import flash.Lib;
import flash.MovieClip;
class Main
{
public static function main()
{
var mc = createMovieClip();
drawRect(mc, 150, 10, 50, 50);
mc.onPress = function()
{
trace(???Clicked!???);
};
mc.onRollOver = function()
{
mc._alpha = 50;
};
mc.onRollOut = function()
{
mc._alpha = 100;
};
}
#if flash6
private static var currentdepth = 0;
#end
private static function createMovieClip(?parent : MovieClip) : MovieClip
{
if(parent == null)
parent = Lib.current;
#if flash6
var depth = ++currentdepth;
#else true
var depth = parent.getNextHighestDepth();
#end
return parent.createEmptyMovieClip(???mc_??? + depth, depth);
}
// the function has been changed a little to fill the box with color
private static function drawRect(mc:MovieClip,x:Float,y:Float,w:Float,h:Float)
{
mc.beginFill(0x00ff00);
mc.moveTo(x, y);
mc.lineTo(x+w, y);
mc.lineTo(x+w, y+h);
mc.lineTo(x, y+h);
mc.lineTo(x, y);
mc.endFill();
}
}
The MovieClip also contains events for onMouseDown and onMouseUp , amongst others; note that these
events are triggered every time the mouse button is used, even if it is not over the visible area of the
MovieClip object.
Pages:
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643