XSL in Adobe AIR

Brian Riggs shows us how to perform client-side XSL/XSLT in an AIR application. Thanks to Brian for shining light on this, and thanks to Mike Chambers for sharing the link on Twitter today. Brian’s post is from May, so many of you may have already seen it.

The solution Brian outlines requires JavaScript because the only XSL toolkit AIR provides is inside of the WebKit HTML rendering engine. Consequently, AIR developers working with the Flash or Flex APIs will need to use an ActionScript-JavaScript bridge. Brian provides a nice code snippet showing how to create that bridge. Great, but still a kludge.

Unfortunately, XSL doesn’t seem to have made it into the Gumbo API for the next version of Flex and AIR. There is also no mention of XSL in Mike Chambers’ September post about AIR 1.5. I have not had an opportunity to pull down a recent nightly build of the Flex trunk to verify that the ActionScript API for AIR continues to lack XSL support, but all indications are that XSL is not present.

A little bit of Googling indicates that I am not alone in desiring XSL capabilities in AIR that do not require a bridge to JavaScript. I know that XSL is not like the hot stuff that Adobe like to tout in its products (OLAP only made it in because of its use in visualization), but it’s a real asset for enterprise developers.

I suspect that Adobe’s plan may be to leave out XSL—and a lot of other large-but-niche APIs—and let teams needing those capabilities include them with FlaCC, the upcoming C/C++ to Flash byte code compiler. (More info about FlaCC, including links to slides and a hi-res presentation video is available here). Specifically, for XSL, Xalan and Xerces could be imported. In truth, I find this to be an attractive solution, in part because I’m sure someone else will go through the hassle of compiling the popular C/C++ libraries to SWCs for me—I will only need drop those into my project.

However, if you are an AIR developer who cannot wait for FlaCC or want to see XSL make it into AIR’s officialy ActionScript API, consider submitting an enhancement request.

Flex 3 addChild() and initialize()

Okay, I’ve walked through all of the code in UIComponent and Container to work this out, so I’m going to share it: the sequence of operations when addChild(child) is invoked on a container and child extends UIComponent.

Since the primary use for this knowledge is managing the initialization portion of the component life cycle, I’ve highlighted the lines where your component may extend the behavior of UIComponent to perform its own operations.

The addChild() code bounces around through a lot of the Container class hierarchy, so I’ve included the class name with the method calls inside the parent’s instance so that you know where in the class hierarchy things get handled.

For simplicity, I skip showing the parameters to method calls and I don’t expand some operations (depicted by italicized text).

  1. Container.addChild()
    1. calls Container.addChildAt()
      1. removes child’s previous parent, if present
      2. calls Container.addingChild()
        1. calls UIComponent.addingChild()
          1. calls child.parentChanged()
          2. performs style setup on child
          3. calls child.stylesInitialized()
        2. invalidates size and display list of parent
      3. calls UIComponent.$addChildAt()
        1. calls Sprite.addChild()
      4. calls Container.childAdded()
        1. parent dispatches “childrenChanged”
        2. parent dispatches “childAdd”
        3. calls child.dispatchEvent()
          1. child dispatches “add”
        4. calls UIComponent.childAdded()
          1. calls child.initialize()
            1. dispatches “preinitialize”
            2. calls child.createChildren()
            3. calls child.childrenCreated()
              1. invalidates properties, size, and display list of child
            4. calls child.initializeAccessibility()
            5. calls child.initializationComplete()
              1. sets processedDescriptors = true
                1. dispatches “initialize”

There you have it: the order of operations when you invoke Container.addChild(). I hope this proves useful.

iPhone OpenGL ES [UPDATED]

Brad Larson of Sunset Lake Software and creator of Molecules gave an excellent presentation about OpenGL ES development for the iPhone at iPhoneDevCamp Chicago this past weekend. Today, he posted the non-NDA-breaking highlights of his presentation online. It’s an excellent resource for anyone starting out with OpenGL development. I find it very inspiring that someone can go from “I know nothing about OpenGL” to finished application in three weeks working only nights and weekends.

UPDATE: With the NDA lifted, Brad has generously released the source code for Molecules!