You are viewing the Articles in the APIs Category

Open Source AS3 APIs

For the past 4 years or so I have provided quite a few AS3 APIs as Open Source to the Flex Community, via my blog. These APIs can typically be found at the Open Source AS3 APIs page however, the page is basically just a URI to a series of arbitrarily added AS3 source classes. It was originally intended to simply serve as a convenient location to access the source, and it had always been my intention to eventually break out all of these APIs into seperate SVN projects.

So with that being said I am finally in the process of making the structural changes I had originally envisioned. Moving forward I will begin the process of creating seperate SVN projects for these Open Source APIs; with the primary goal being to provide practical APIs that only require minimal (if any) dependencies on additional libraries, complete test coverage via Flex Unit 4 and Mavenized builds.

The first project to move over to the new project structure will be the AS3 collections project as the classes in this package, specifically HashMap, have proven to provide the most value according to community feedback.

So stayed tuned!

XMLAsset: API for embedded XML files

Back in February I blogged about how to embed arbitrary file types in ActionScript (see “Embedding assets with application/octet-stream” for the complete post). That post was inspired by some work I was doing at the time which involved embedding XML files in ActionScript as an alternative to using the <mx:Model> tag in mxml. In the time since I have created a simple yet useful class which can be utilized as both a utility a concrete or a base class to facilitate decoding an embedded XML file to an XML object.

XMLAsset provides an API which allows for the decoding of an embedded XML file (via the [Embed] metadata tag / compiler directive) to a native XML object. There are three different ways XMLAsset can be implemented, the first of which is to simply create an instance of XMLAsset and pass the constructor a reference to an embedded XML asset as follows:

In the above example we are simply creating an instance of XMLAsset and passing a reference to an embedded XML asset from which to decode to a native XML object. From there we can access the decoded xml object as needed.

The second implementation is to sub-class XMLAsset and pass in a reference to a specific embedded xml file by calling super on XMLAsset, as can be seen in the following:

In the above example we are simply extending XMLAsset and passing a reference of the embedded asset to super. From there we can access the decoded xml object as needed.

The third way to utilize XMLAsset is to invoke the static createXML method directly. To do so we pass in an embedded XML asset just as we did in the first to examples. The createXML method returns a native XML object. An example is as follows:

One thing to keep in mind is if the file which is to be embedded contains XML but does not have the recognized .xml extension the compiler will throw an error. In such cases you need only specify the mimeType as “application/octet-stream” in order to embed the file without error, however I suggest always using the .xml extension whenever possible as in the event the file should contain invalid XML mark-up you will get an error during compilation rather than at runtime. In any case embedding an XML file with an extension other than .xml is very simple, an example of which can be seen in the following:

And that’s all there is to it. Enjoy.

AJAX Debugger beta 2.0

Recently, I wrote a simple AJAX debugger which can be useful in the debugging of complex types such as Objects, Arrays, JSON etc.

The AJAX Debugger traces out all inherited and “own” properties of user defined Object instances, properties/values of an Object, indexes of an Array, etc. – to a div with an id of “console” within an application.

To use the AJAX Debugger, simply include debugger.js in your application during development and create a div on the page with an id of “console” to serve as an output panel (I plan to implement the creation of the console div automatically in the next release).

To log output to the console, use the debugger’s trace function:

An upgrade to version 1.0 will be made within the next few weeks, allowing for the ability to launch the console in a separate window independent of the application itself.

An example of can be found
here

The AJAX Debugger can be downloaded
here.

Feel free to email me with your thoughts and / or ideas to make the Debugger better.