Saturday, April 4, 2009

Tricky Flex

My first foray into Flex...by hand. At this time I can only afford development tools in the Eclipse price range. Anyone know of a good (=free) plugin?

Application lifecycle intrigues me, and for Flex it can be a little tricky.
Here's a riddle! Can you guess the output of the following: (no fair if you are a Flex expert):

<mx:Application name="##" xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Label text="before any scripts"/>
<mx:Script>
    import mx.controls.Label;
    [Bindable] private static var cc:int = 0;
    private var label1:Label = new Label();
    private var label2:Label = new Label();
    private var label3:Label = new Label();
    private var label4:Label = new Label();
    [Bindable] private var bounded1:String = ""+(++cc);
    [Bindable] private var bounded2:String = "";
</mx:Script>
<mx:initialize>
    bounded2 = ""+(++cc);
    label1.text = "One";
    addChild(label1);
    buildGui();
    label5.text = "set from inside";
</mx:initialize>
<mx:Script>
    private function buildGui():void {
        label2.text = "Two";
        addChild(label2);
    }
    override protected function createChildren():void {
        super.createChildren();
        label4.text = "Four";
        addChild(label4);
    }
</mx:Script>
<mx:creationComplete>
    label3.text = "Three";
    addChild(label3);
</mx:creationComplete>
<mx:Label text="still gets added ahead of any in the script"/>
<mx:Label id="label5"/>
<mx:Label text="{cc}"/>
<mx:Label text="{bounded1}"/>
<mx:Label text="{bounded2}"/>
</mx:Application>


I will post the answer just as soon as I figure out how to get a .swf to display on this blog.