Here is what I did to build a similar crop area component. I don't
know if it's the cleanest, but it works.
I extended a UIComponent, added frameWidth & frameHeight properties
and overrode the UpdateDisplayList with the following:
override protected function updateDisplayList(unscaledWidth:Number,
unscaledHeight:Number):void {
super.updateDisplayList(unscaledWidth, unscaledHeight);
//must set blend mode to layer for BlendMode.ERASE to
work
this.blendMode = BlendMode.LAYER;
// Draw a rectangular mask to darken the cropped out parts of
the image
var myMask:Sprite = new Sprite();
myMask.graphics.beginFill(0x000000);
myMask.graphics.drawRect(0,0,unscaledWidth,unscaledHeight);
myMask.graphics.endFill();
myMask.alpha = .75;
this.addChild(myMask);
//draw a box to represent the "cropped" area
var myCrop:Sprite = new Sprite();
myCrop.graphics.beginFill(0xFFFFFF);
myCrop.graphics.drawRect(0,0,frameWidth,frameHeight);
myCrop.graphics.endFill();
this.addChild(myCrop);
myCrop.blendMode = BlendMode.ERASE;
//center the cropped area box
myCrop.x = (unscaledWidth - frameWidth)/2;
myCrop.y = (unscaledHeight - frameHeight)/2;
}
On Oct 26, 2007, at 12:20 PM, Kevin wrote:
this may be a silly question, but how exactly do you draw something
in "reverse order". I understand the concept, but I am not sure
how to do it. Can you do it with the Graphics class or do you need
to dig deeper?
Thanks,
- Kevin
On Oct 25, 2007, at 12:13 AM, Jon Bradley wrote:
On Oct 24, 2007, at 9:08 PM, shaun wrote:
Could you explain this idea of "reverse order" a bit more or
provide a
url with some information about how to do this. I dont think I
really
understand how to implement it.
"Reverse Order" is the opposite ordering of control points, or
knots, on a curve or sequence of lines. Technically reverse
drawing order is counter-clockwise. All Graphics class functions
in AS3 are clockwise.
The most obvious usage of drawing in different directions,
clockwise or counter- clockwise, is so that you can create holes
(cutouts) within fills.
..... example attached below.
- jon
In AS2, here's a quickie example.....
function drawRect(target:MovieClip, x:Number,y:Number,
width:Number, height:Number, reverse:Boolean):Void {
if (!reverse)
{
target.moveTo(x, y);
target.lineTo(x+width, y);
target.lineTo(x+width, y+height);
target.lineTo(x, y+height);
target.lineTo(x, y);
}
else
{
target.moveTo(x,y);
target.lineTo(x, y+height);
target.lineTo(x+width,y+height)
target.lineTo(x+width,y);
target.lineTo(x,y);
}
}
var mc:MovieClip = this.createEmptyMovieClip("some_mc", 0);
mc.beginFill(0x000000);
drawRect(mc, 0,0,100,100,false);
drawRect(mc, 10, 10, 80, 80, true);
drawRect(mc, 45,45,100,10,false);
mc.endFill();