return undefined;


Come heckle me at 360|Flex Atlanta

Posted in 360|Flex, Flex, flexmdi, pointless blather by Ben on the January 29th, 2008

In just under a month, the amazing Tom and John will, once again, orchestrate what is sure to be an amazing conference. If you have any desire at all to improve your Flex skills, meet fellow developers, find a Flex job, hire a Flex developer or just have a really good time with lots of smart, cool people you should definitely attend. For $480 you can’t beat it with a stick.

As the title implies, I will be speaking at the conference. My session is titled “Creating Flexible Components for Reuse and Distribution” and will discuss just that. I will be covering considerations and practices that are useful when you want to create something that will be useful beyond your immediate need or project. Most of the main ideas will be accompanied by examples from flexmdi since reuse and flexibility were main goals of the project, but the concepts will definitely be widely applicable. I would consider it an intermediate level session so you don’t need to be a guru to attend, but hopefully the content will be interesting to developers of all skill levels, including you rock stars out there. Last time I checked I was speaking opposite Ben Forta so if you’re a CFer I will understand if I don’t see you. Otherwise come join me! The session will be pretty free-form and casual; if people want to shout out questions (or insults, whatever) in the middle thats fine by me. In fact, I hope there will be audience participation in the form of questions, comments, alternative approaches, etc. Should be a good time.

So I hope to see you in the audience, but even more so I hope to see you at the conference. Tom and John put on amazing events, have amazing passion for our industry and deserve nothing less than a stellar turnout. If you’ve never been to a 360 event, you owe it to yourself to experience it firsthand. Its awful friggin’ cool. So come out, learn something, meet someone or just enjoy the ATL. I promise you won’t regret it.

Hidden gem of the Flex framework: LayoutContainer

Posted in AS3, Flex by Ben on the January 8th, 2008

Every now and then I stumble across something in the Flex framework that I am both surprised and sorry I didn't know about sooner. Like the fact that CheckBox has a built-in clickHandler method. Duh. LayoutContainer just may be one of the most useful classes around, especially if you're creating components you want to be reusable and flexible. First, a little background.

Its fairly common knowledge that VBox and HBox both extend Box and do nothing more than set a direction property. What may be a bit less obvious is the fact that the direction property is actually applied to an internal layoutObject property. In the case of Box (and by extension VBox and HBox), layoutObject is of type BoxLayout. As it turns out, Canvas uses an internal layoutObject as well, but in that case its an instance of CanvasLayout. Now notice that my references to both BoxLayout and CanvasLayout are not linked to the corresponding documentation. This is because Adobe has specifically excluded them from the documentation because, for whatever reason, Joe Developer isn't supposed to directly use them.

When I first discovered this I set about using them anyways because I had been struggling to find an optimal solution to a problem for a couple of days. Sure they always say things "may not be supported in future versions" but when was the last time they actually pulled something out and besides, where's your sense of adventure? I was on my way to creating a base class that could act like a Canvas, VBox or HBox using some intelligent switching between what type of layoutObject (and direction) it used. I was happy. Well, I didn't get far before I started hitting errors due to not implementing some deeply nested interface or some other nonsense. I was no longer happy. Thankfully, while digging through source and documentation I stumbled onto LayoutContainer. Lo and behold it does exactly what I was trying to accomplish! By changing the layout property between "absolute", "vertical" and "horizontal" (defined as constants on ContainerLayout), you can have your container lay its children out like a Canvas would (direction = ContainerLayout.ABSOLUTE) or like a Box would (direction = ContainerLayout.VERTICAL | ContainerLayout.HORIZONTAL). I suppose this is only exciting if you have a need for this kind of functionality, which, who knows how common that is but it was an absolute life saver on my recent task.

Stay tuned for where this technique is getting applied but I will leave you with the chunk of code from LayoutContainer that does the magic referenced in this post.

public function set layout(value:String):void
{
    if (_layout != value)
    {
        _layout = value;

        if (layoutObject)
            // Set target to null for cleanup.
            layoutObject.target = null;

        if (_layout == ContainerLayout.ABSOLUTE)
            layoutObject = new canvasLayoutClass();
        else
        {
            layoutObject = new boxLayoutClass();

            if (_layout == ContainerLayout.VERTICAL)
            {
                BoxLayout(layoutObject).direction =
                    BoxDirection.VERTICAL;
            }
            else
            {
                BoxLayout(layoutObject).direction =
                    BoxDirection.HORIZONTAL;
            }
        }

        if (layoutObject)
            layoutObject.target = this;

        invalidateSize();
        invalidateDisplayList();

        dispatchEvent(new Event("layoutChanged"));
    }
}

While the implementation may not be rocket surgery it is extremely useful at times. In fact, you may have even used one of LayoutContainer's subclasses before, its a little class called Application.