Comments: get visible width/height of a display object

Very useful, thanks for that.
I always struggled with the text bounding boxes measures, which I needed for animated, masked menus ...
This will definitely help.

Posted by adehaas at June 2, 2009 05:25 AM

@visibledimensions: yes, that would be useful. it's left as an exercise for the reader.

@juan charvet: let me know if you encounter any problems with the code.

Posted by colin at May 28, 2009 02:30 PM

Thanks for this, Colin. I'll put it to test on a project I currently have this exact challenge with.

Posted by Juan Charvet at May 28, 2009 09:16 AM

hi,

very useful info, thanks. wouldn't it make sense to add an additional method, such as getVisibleDimensions() that, for example, returns a point object containing the width and height? that way the bitmap data would only have to be created once for situations when you need both the visible width and height at the same time...

Posted by visibledimensions at May 28, 2009 08:12 AM

@nishant: the draw-to-bitmap approach is not as fast as a native player implementation would be, but it's still pretty darn fast, and should be fine for most purposes. i would think you could run the functions thousands of times per frame without much/any slowdown. popular pixel-perfect collision detection schemes use similar code successfully. i'd definitely give it a try. (scaling is a really neat idea, btw. let me know how it goes!)

Posted by colin at May 27, 2009 03:09 PM

I eagerly read thru the whole thing hoping for a diamond of a discovery.

Good attempt, but sadly this will be quite a performance issue for me if I use this. How about you scale the object very small before drawing the bitmap, you can calculate the bounds to a good precision even then I guess. I'll give it a try :)

Posted by Nishant at May 27, 2009 05:53 AM

@kudoshinichi: a generalized function that loops recursively through all children, catalogs their depths, then removes, unmasks, measures, reattaches, and remasks, in addition to measuring text metrics, would be significantly more work to write and maintain, would be more error prone, would be slower, would not even work with some components (e.g., flex framework) that don't expose skin children through getChildAt(), and might trigger unwanted side-effects such as layout code execution.

Posted by colin at May 26, 2009 03:43 PM

Thanks for registering this as a bug with Adobe. Hopefully, they will listen. I am truly baffled why this isn't a built-in.

Posted by Matthew Donadio at May 26, 2009 10:55 AM

Why don't you just loop through the parent container and removeChild, get the size then add child again?

Posted by kudoshinichi at May 26, 2009 05:58 AM

Very useful functions, I've run into such issues many times, back from the days of actionscript 2, I can only wonder why Adobe hasnt got round to implementing such functions!

Posted by Ncu at May 26, 2009 04:17 AM