The new scrollRect property in AS3 DisplayObjects is pretty cool. If you haven’t run into it yet, it’s a fairly simple way to set a rectangular window on a larger piece of content without the hassle of drawing a rectangle and using a mask and inverse positioning the content… For the most common masking operations it comes in really handy.
And then reality sets in. You want to check the height of your content so you can set up boundary conditions for the scrolling behavior. But! When you get the height property, it’s been modified to reflect the fact that the content is now masked. You don’t get the “native” height anymore. What’s even worse, this update to the property doesn’t take effect until the next frame (following a change to scrollRect — and you’ll need another frame if you’re doing this the first frame the asset is on the stage — YMMV), so you’ve got to add (and remove) a temporary enterframe event listener … it’s a total mess. Thinking about using getBounds instead? Save yourself the trip. It works (as in “doesn’t work”) the same way.
Now suppose you suck it up and decide to deal with waiting a frame after your content fires onResize. You can handle a little add/remove listener juggling. No biggie. Alas, you’ve got no way to get access to your original height once a scrollRect has been set. You could temporarily remove the scrollRect, but that change won’t take effect until the next frame. Gah!
So, I went digging through the docs to find an alternative. The only thing that looked even remotely promising was the transform property. I went through my code and replaced references to content.height with content.transform.pixelBounds.height and I was in business. As far as I can tell, this property responds appropriately to scale, rotation, etc while omitting any scaleRect clipping. However, if you were to grab content.parent.transform.pixelBounds.height, it would take the clipping into account.
Hopes this helps someone else out there…
— UPDATE —
You know what’s awesome? If the DisplayObject isn’t on the stage, pixelBounds values are the “native” x, y, width, and height you’d expect looking at the Flash IDE property inspector. Times 5. Don’t look at me like that. Try it. You’ll get values five times bigger than you ought to. Maybe it’s something to do with twips…
The whole idea of this exercise was to find a way to grab the height of a DisplayObject without a bunch of if/else hassle. But if you’ve got to sniff for a stage object, you might as well sniff for the scrollRect object itself — and the value you read won’t be subject to the frame delay. That’s only a problem when reading it via the height property. Hope that clears up any confusion.