Introducing the IconLoader component

9 09 2007

I’ve made my first contribution to the flexlib project: the IconLoader component.

The IconLoader control has an interface similar to <mx:Image>, but instead of displaying a PNG, JPEG or other bitmap image, it displays an icon. The control understands the Windows .ico and Mac OS .icns file formats. Icon files usually contain images at various sizes. The IconLoader control will choose the most appropriate size given the size of the control itself. E.g. if the control is explicitly sized to 40 pixels wide and 42 pixels high, and the source icon file contains a 32×32 icon, that icon will be used. Like with <mx:Image>, IconLoader has a scaleContents property. When this is set to true, the icon is scaled to fill the control’s bounds.

The source property can either be set to a string or an embedded object. Strings are interpreted as URLs, and the icon file is retrieved and parsed. It’s also possible to use the @Embed directive to set the source property to an embedded byte array.

A quick note on the latter usage of the source property. Any arbitrary data file can be embedded in a flex app by setting the mime-type property of the @Embed directive to application/octet-stream. The embedded class extends ByteArray, so it’s trivial to examine the contents of the file. Thanks to Doug McCune for turning me on to this technique.





Using a signed Java applet as a Flex helper – Part 1

29 08 2007

I want to talk about a proof-of-concept I developed a few months back. The problem was that we needed a Flex 2 application to be able to launch an external, native application to edit a file. Since Flex is strictly limited in how it can interact with the file system and the native OS, this seemed impossible. But then I had the idea of using a signed Java applet to do the hard work. Because it’s Java code, it can interact with the file system and do things that Flex can’t do — like launch external applications.

OK — it’s not an original idea. The Artemis project from EffectiveUI is doing something similar, but for AIR applications.

Keep in mind that I’m not a Java programmer. Nor am I a JavaScript programmer. I’m probably making all sorts of mistakes that will induce a lot of eye rolling. Just try to keep it to yourselves. (I do know Flex and Actionscript, so feel free to openly mock egregious errors in those domains.)

I’m going to break this posting into two parts. In the first part I’ll show how to create a trivial Java applet, have it load simultaneously with a Flex application, and show how the Flex application can communicate with the applet. In the second part, I’ll provide a slightly less trivial Java applet that will open an external editor, and show how to sign the applet and deal with thread synchronization issues (!!).

Read the rest of this entry »





Using a signed Java applet as a Flex helper – Part 2

29 08 2007

In the previous post, I showed how to create a Java applet, embed it in the same HTML page that wraps a Flex application, and call a public method in the applet from Flex. In this post, I will demonstrate creating a signed Java applet that will help a Flex application interact with the native OS.

Read the rest of this entry »