ulfben

getVisibleBounds in AS3

Dec 7th, 2016
145
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //courtesy of Colin Moock: http://www.moock.org/blog/archives/000292.html
  2. /**
  3.  * Returns the distance from the registration point of the specified
  4.  * object to the bottom-most visible pixel, ignoring any region
  5.  * that is not visible due to masking. For example, if a display
  6.  * object contains a 100-pixel-high shape and a 50-pixel-high mask,
  7.  * getVisibleHeight() will return 50, whereas DisplayObject's
  8.  * "height" variable would yield 100.
  9.  *
  10.  * The maximum measureable dimensions of the supplied object is
  11.  * 2000x2000.
  12.  */
  13. function getVisibleHeight (o:DisplayObject):Number {
  14.     var bitmapDataSize:int = 2000;
  15.     var bounds:Rectangle;
  16.     var bitmapData:BitmapData = new BitmapData(bitmapDataSize, bitmapDataSize, true, 0);
  17.     bitmapData.draw(o);
  18.     bounds = bitmapData.getColorBoundsRect( 0xFF000000, 0x00000000, false );
  19.     bitmapData.dispose();
  20.     return bounds.y + bounds.height;
  21. }
  22. /**
  23. * Returns the distance from the registration point of the specified
  24. * object to the right-most visible pixel, ignoring any region
  25. * that is not visible due to masking. For example, if a display
  26. * object contains a 100-pixel-wide shape and a 50-pixel-wide mask,
  27. * getVisibleWidth() will return 50, whereas DisplayObject's
  28. * "width" variable would yield 100.
  29. *
  30. * The maximum measureable dimensions of the supplied object is
  31. * 2000x2000.
  32. */
  33. function getVisibleWidth (o:DisplayObject):Number {
  34.     var bitmapDataSize:int = 2000;
  35.     var bounds:Rectangle;
  36.     var bitmapData:BitmapData = new BitmapData(bitmapDataSize, bitmapDataSize, true, 0);
  37.     bitmapData.draw(o);
  38.     bounds = bitmapData.getColorBoundsRect( 0xFF000000, 0x00000000, false );
  39.     bitmapData.dispose();
  40.     return bounds.x + bounds.width;
  41. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×