While adding cropping to an image editing component, I had to learn a few things about displayObject.mask and displayObject.scrollRect:
- mask and scrollRect are mutually exclusive: You cannot use both at the same time.
- Grant Skinner has got a nice introduction into scrollRect.
- Mask can have any form. Andrew Trice features a nice bundle of samples.
- ScrollRect is of type Rectangle and hence, the form is always a rectangle.
- Mask does not change the size of the displayObject.
- ScrollRect does change the size. Ticore Shih has got the examples.
- There is a catch with 6. While scrollRect does change the size, you cannot know when this will happen, really! It might be suitable for a random number generator. UIComponent.calllater() does not bring you anywhere.
It has been reported as a bug in FP-177 just two weeks ago. Though I am not sure what FP 9.2 Code Complete means and the comment is somewhat unclear to me. - The workaround is either using the dimension of scrollRect or redrawing the DisplayObject as described by Ticore. (At least the code shows it; I don’t exactly know what he says in Chinese…)
19 December 2008 at 2:41 |
re: 1, the wording implies you can’t mask an object that has a defined scrollrect. You can; and in fact it’s a nice technique to allow for blurred edges of masked content. In order to get the mask to honor transparency, both maskee and masker need to be cached as bitmaps. However, without using scrollRect, the maskee can’t exceed 2550 pixels in either direction (this may be higher in 10). this is really easy to exceed with any non-trivial data set. Using scrollrect, you can achieve the effect because the cached bitmap is only as large as the scrollrect height or width.
19 December 2008 at 8:53 |
Thanks for the clarification, Brenden. In fact, I relied on the linked comment of Jason Szeto and knew that mask and scrollRect are troublesome in Flex if coming together.
24 February 2009 at 23:09 |
6 is a pretty tricky one. It makes it very difficult to find the unmasked size of the display object. I have a solution here: http://usecake.com/meta/find-the-height-and-width-of-a-sprite-with-a-scrollrect.html
25 February 2009 at 11:24 |
Interesting method, Joe. Thanks for the link.