Why does Flash use the entire height of the masked object, and not just the visible area?

The problem is that I set the property .mask object Sprite , Object Sprite still returns his full height, when I call Sprite.height . So I decided that an easy way to overcome this would be to override the getter property.

Now ... although it worked if I add this masked Sprite object to another Sprite object , the new Sprite object will tell it height as a Sprite mask , even if I override the property to return only the height of the visible area due to the mask. Thus, it seems that Flash is ignoring the fact that not all content is visible, but still automatically increases the new height of the Sprite object , as if on a masked <i> Sprite .

So, I am wondering if there is a workaround, so I can add this masked object to any other DisplayObject , knowing that it will be changed only for what is visible in the masked object.

Thanks for any help.

EDIT

Here is a sample code.

var content:Bitmap = new Bitmap(new BitmapData(50, 100, false, 0x000000));
var container:Sprite = new Sprite();
var mask:Bitmap = new Bitmap(new BitmapData(50, 50, false, 0x000000));

container.mask = mask;

container.addChild(content);

trace(container.height) // this should return 50 instead of 100
+5
source share
4 answers

So for those who are interested, I managed to come up with a workaround. What really annoys me is that DisplayObject.scrollRect doesn’t update the dimensions right away until Adobe gets off their ass and fixes it, that’s what you need to do.

.scrollRect, , , , . , .scrollRect, , , , .width .height . , READY , , .

, , , , .scrollRect , , .scrollRect. , Stage , .scrollRect , MyClass. MyClass .visible false, . 1 , , , .scrollRect.

, , , MyClass MyClass.READY , , .visible true . , MyClass , , , , MyClass.scrollRect.

, , , , , , Adobe - . , , , , !

+2

xLite, . , -, .

 var content:Bitmap = new Bitmap(new BitmapData(50, 100, false, 0x000000));
 var container:Sprite = new Sprite();
 content.scrollRect = new Rectangle(0, 0, 50, 50);

 container.addChild(content);

 new BitmapData(1,1).draw(content);//this line would help
 trace(container.height);
+2

, :

  • ( DisplayObject, ) BitmapData.
  • BitmapData - BitmapData getPixel32().
  • , - .

getMaskedDimensions(child:DisplayObject):Rectangle. , . , !

0

. , , , , , . getRect getBounds , .

, "getMaskSensitiveRect", . , getRect , , , null, getRect . , .. , , , , .

Remember to redefine the setters for width and height, as changing the width or height of the DisplayObject does indeed scale, and it does this relative to that internal size, not your redefined width and height. What you would need to do in the setter is to call the getMaskSensitiveRect method and calculate the scale using this and your desired width, and then set the scale to scaleX and scaleY.

0
source

All Articles