“setActualSize” actually doesn’t

February 7, 2007 at 10:36 pm 6 comments

As a relatively new Flex user, I run into issues every now and then where flex doesn’t behave as I expect it to. Recently I was trying to resize an object dynamically through a “click-and-resize” interface. I looked over the API and found a “setActualSize” method on the UI component class that seemed like it would work well, but when I used it, my shapes weren’t actually resizing. A half hour of weeding through stack traces helped me discover this comment in the UI component code:

* Sizes the object.
* Unlike directly setting the <code>width</code> and <code>height</code>
* properties, calling the <code>setActualSize()</code> method
* does not set the <code>explictWidth</code> and
* <code>explicitHeight</code> properties, so a future layout
* calculation may result in the object returning to its previous size.
* This method is used primarily by component developers implementing
* the <code>updateDisplayList()</code> method, by Effects,
* and by the LayoutManager.
* @param w Width of the object.
* @param h Height of the object.
public function setActualSize(w:Number, h:Number):void

This is the issue I’m seeing – a future updateDisplayList() call from the canvas my object is on is immediately resizing my object after my call to setActualSize. In fact, I think my call to “setActualSize” is causing the canvas to invalidate my object and immediately call setActualSize again with the wrong width and height, which is kind of ironic, if you think about it.

The preferred solution in my case is to set the width and height properties of my object explicitly. Another option is to override the “updateDisplayList” method to take width and height changes into consideration. Methods with titles like this frequently lead me down the wrong path in Flex, since they rarely do the sorts of things my Java brain thinks they would.

Getting used to explicitly setting public properties is just part of the transition from more traditional OO languages to Flex.  At least you can override the property’s setter with a method, upholding the principal of encapsulation.


Entry filed under: flex.

Bruce Eckel, Flex, and Improving the Developer Experience

6 Comments Add your own

  • 1. Carlos Montes  |  July 7, 2007 at 3:49 pm

    Not to dig up old entries but I ran into the same issue yesterday with an HBox I was using to hold a Flash component (Flash CS3 component kit). Overriding the setActualSize function did not do what I wanted, even though the initial values were correct.

    Finally, I added another line to my function: super.setActualSize(w, h); Calling the super.setActualSize function with the values given to me solved the issue. I didn’t quite understand why that worked, but reading your article sheds some light on it.

    Just sharing the knowledge! 🙂

  • 2. RJ  |  July 7, 2007 at 3:52 pm

    Thanks! New knowledge on old entries is always appreciated!! It’s the people coming to say “flash sucks!” on a post that’s 6 months old that seems weird to me. 🙂

    Glad you got it to work – I’ll give that a shot next time.

  • 3. Carlos Montes  |  July 12, 2007 at 6:33 pm

    It seemed to work, but I got pulled into something else so couldn’t explore it further. I will definitely be letting you know what I find.

    By the way, I met some of your colleagues (you work for effective UI, right?) at the MAX conference last October. At the time I was working for MySpace.

    Anyway, have fun flexing!

  • 4. RJ  |  July 12, 2007 at 7:38 pm

    MySpace, eh? Nice! How did that go? Who are you working with now? Will you be at MAX again this year? I do indeed work for Effective UI. I don’t think I personally will be at Max this year, but a couple of our guys will be speaking. Should be pretty good stuff. Do you mainly do contract work?

    I tried to email this to you but it looks like the email address you gave the blog bounced….

    Anyway, thanks for the blog comments!

  • 5. Carlos Montes  |  July 13, 2007 at 10:57 am

    Hey, sorry about that! I forgot the M in my last name. D’oh! I work for http://www.imeem.com now having left MySpace very recently. I don’t do much contract work actually. I think I will be at MAX again this year, but won’t be speaking or holding sessions like last year. If ever you get a chance, I recommend going to MAX.

    Working at MySpace was amazing. You’d be surprised how much technology actually goes into that website. Definitely had some good times there, but it was definitely time to go.

  • 6. Sri  |  December 12, 2007 at 6:38 pm

    Ah thanks for the tip on setActualSize. Man that was annoying. Who would have though you’l have to set these sizes explicitly!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed

February 2007
    Mar »

Recent Posts

%d bloggers like this: