Here’s an interesting little hack that has, at a stroke, saved me enormous headaches with getting Flash-authored content (IUMovieClip) to play nice in Flex apps.
A little background: the Flash stuff I get from my designer does not conform to what Flex expects from its components. Things stick out the sides, animate all over the place, there’s massive masked objects all over the shop that totally screw up the placement in Flex, especially in a fluid layout where I am relying on horizontalCenter and verticalCenter to keep things positioned correctly. Scrollbars suddenly appear on my application, elements start shaking and shuddering as they animate when they would ideally stay perfectly still.
I was sure there would be a way to fool Flex into thinking my UIMovieClip-extending objects are not changing their height and width. I tried overriding the getter for width and height – no dice.
Then I thought I’d try overriding the getter for “bounds” – the rectangle that defines the size of the display object. It works! Of course then you aren’t getting the magical auto-alignment that the Flex framework offers .. but in the cases where your content doesn’t need that treatment but does need to be positioned using, say, horizontalCenter, it’s perfect.
It’s as simple as:
override protected function get bounds():Rectangle {
var b:Rectangle = super.bounds;
b.width = 200;
return b;
}
.. of course, “200″ is just an arbitrary number.
To see how this works in practise, have a look at an example (wordpress is refusing to embed my Flash inline for some reason). View source is enabled; ignore the package names, I just hacked the example together in the midst of building a client’s website, and I can’t be bothered to make a separate project for the example).
P.S. I have no idea if this is already common practise; I tried googling for solutions but found nothing. Comments welcome.
P.P.S. The name “flesh hack” is quite apt, I think, to describe a programming trick to get Flash and Flex to work well together – the struggle is often quite brutal …




Looks like a worthy hack to me! Clipping the content wouldn’t have the same effect as you really still want to see it.
Some of the random battles with Flexes layout routines have taken years off my life, never mind the flesh…
Hi Josh. There’s actually a feature in the Flash Component Kit for what you’re trying to do. The details are fuzzy in my mind, but I believe if your designer puts a movieclip in the timeline with an instance name of ‘boundingBox’, the UIMovieClip will use the bounds of that movieclip as its reported size rather than the true size of the content. That way, the adjustments to the bounding box are under your designers control, and can adjust as the content moves from frame to frame if necessary.
Overriding measure() and setting measuredWidth/measuredHeight should work too ?