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.

Tuesday, May 20, 2008

[A Grizzly Groovy Echo]

Well, I'm kicking off my first blogging experience, having been prompted to do so after attending the absoultely wonderful talk by Jared Richardson on Career 2.0 given at the TriJUG this month. He will be giving a talks on the 2008 No Fluff Just Stuff tour, so be sure to sign up and check it out.


My first JavaOne was very cool. I was freshly spurred to look at Grizzly again after attending the inspiring presentation by Jean-Francois Arcand and thought, just for kicks (and to get content for a blog :)) I would try to implement his "Grizzly Echo Server in 20 lines" in Groovy, my new favorite programming language with an eye to "just how short it can be with only what is provided by Groovy and Grizzly".
Here it is in 19 lines: (10 if you ignore the imports, blank line and formatting to fit the blog)


import com.sun.grizzly.*
import com.sun.grizzly.filter.*
import com.sun.grizzly.util.*
import java.nio.*

def protocolChain = new DefaultProtocolChain()
protocolChain.addFilter(new ReadFilter())
protocolChain.addFilter(new EchoFilter())
def pcih = [
    'poll':{protocolChain},
    'offer':{instance -> true}
]
def controller = new Controller()
def tcpHndlr = new TCPSelectorHandler()
tcpHndlr.port = 8080
controller.addSelectorHandler(tcpHndlr)
controller.protocolChainInstanceHandler =
    pcih as ProtocolChainInstanceHandler
controller.start();

Just paste into a groovyconsole and hit Ctrl-R. Use a typical telnet client to access. Never mind the "Hotel California" effect!
----
Lesson Learned: It is really easy to add links into a blog!!!