简体   繁体   中英

Flash AS3: How to Resize a Rect within another Rect?

I've got a tricky one that's stumping me, could you take a quick look over it please...

I draw a rectangle within another rectangle like this (I use it as a mask):

CanvasBorder.graphics.beginFill(0xf0ff00,0.1);  
CanvasBorder.graphics.drawRect(100,100,550, 300);
CanvasBorder.graphics.drawRect((stage.stageWidth/2-Canvas.width/2),(stage.stageHeight/2-Canvas.height/2),250, 150);
CanvasBorder.graphics.endFill();

effectively its a 550x300 box with a 250x150 cutout.

Within one of my functions I need to resize the INNER 'cut-out' box from 250x150 to 150x100 - but keep the OUTER box exactly the same.

Normally when I'd resize a normal rectangle I'd do this:

rectangle .width = 150;
rectangle .height = 100;

But this solution doesn't work and I don't know how to reference the cutout of the shape. Any ideas please I'm really struggling with this one and can't find anything on google.

thanks for your time

ChainsawDR

Maybe you can create ANOTHER Sprite or Shape like this:

// somewhere in your code declare the rectangleMask
var rectangleMas:Shape;


rectangleMask = new Shape();
// draw the rectangle the same way
// and add it to CanvasBorder (I assume that CanvasBorder is a DisplayObjectContainer)
CanvasBorder.addChild(rectangleMask);

Then you can just do the resize as you want:

rectangleMask.witdth = 150;
rectangleMask.height = 100;

If you want that rectangle to be a mask of CanvasBorder you can do this:

CanvasBorder.mask = rectangleMask;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM