No Clean Feed - Stop Internet Censorship in Australia
«
»

Flash, Flex

overriding bounds: flesh hack

09.12.08 | 3 Comments

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 …

related

3 Comments

have your say

Add your comment below, or trackback from your own site. Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

:

:


«
»
Close
E-mail It