How to erase an area in a BitmapData object?

actionscript, apache-flex, bitmap, flash, graphics

Solution

Got it working with the following code:

        var shape:Shape = new Shape();
        shape.graphics.beginFill(0x000000, 1); // solid black
        shape.graphics.moveTo(points[0].x, points[0].y);

        points.forEach(function (p:Point, i:int, a:Array):void {
                shape.graphics.lineTo(p.x, p.y);
            });
        shape.graphics.endFill();
        data.draw(shape, null, null, "erase");

Problem

Flex 3, ActionScript 3, Flash player 9. I have a picture in a BitmapData object. And an array of points. I nead to erase the part of the picture inside a polygon specified by the points. In other words, draw a polygon specified by the points and fill it with transparency. Any ideas on how it can be done?

Original source