Welcome!

.NET Authors: Liz McMillan, Peter Silva, Yakov Werde, Matthew Pollicove , Corey Roth

Related Topics: .NET

.NET: Article

The Xamlon Story

.NET code + XAML markup = Flash SWF

XAML has a number of advantages. Control and attribute hierarchies are more apparent. Tools can easily be written to generate or interpret the markup. There is useful separation of UI and procedural code.

Simple XAML documents render in a browser much like an HTML Web page. As your application becomes more complex, events and procedural code must be added in a separate file. These are compiled together using the MSBuild utility.

This model is exactly the approach taken by Xamlon. You craft the interface elements in XAML and write managed code in C# or VB to handle logic and events. These are compiled into standard .NET MSIL (Microsoft Intermediate Language). The byte codes from the resulting DLL pass through a post compiler that maps .NET to Flash byte codes. The resulting SWF file can run in any browser or operating platform that has the Flash player.

The Xamlon Development Environment
There is decent support for Visual Studio 2003, including C# and VB.NET. Visual Studio 2005 will be supported at release time, including the inexpensive Express editions. Debugging relies on a Console.WriteLine technique; this is certainly not as smooth as standard .NET de-velopment. Hopefully a future version will fully integrate with the excellent Visual Studio debugging suite.

Notepad or a suitable text editor can be used with the .NET Framework SDK 1.1 if Visual Studio is not available. Xamlon uses the CSWF.exe command line compiler. This command line statement takes an XAML input file, two reference DLLs, and a C# source file to produce the expense.swf output file:


cswf/xaml:expensereport.xaml /r:
SwfNative.dll,XamlControls.dll
/embed:XamlControls.dll /out:
expense.swf /verbose /clean /
launch /compress ExpenseReport.cs
The .NET framework is not required on the client. All .NET language syntax is compiled to MSIL and then prost-processed through the Xamlon command line compiler to produce a standard Flash SWF file. In Visual Studio, this process is transparent to the developer. You can see the steps involved by opening the Output pane after compilation. The final step creates a sample HTML page that embeds the generated SWF. This is useful for testing and snipping an HTML code sample (see Listing 1).

Not all .NET classes are supported. Xamlon does comply with IL ECMA #335. There are basic Winform controls, databinding for controls, DataSet, and Web service support for connectivity to standard Web services like ASMX. GDI+ programmers will be pleased that basic graphic calls are converted to Flash. This feature can be used with or in place of XAML layout.

Flash player 6 or above is needed to run the SWF file. Xamlon calls this "Zero-Install Framework" (ZIF) since the .NET Framework is not required and the resulting file has an extremely small footprint. SWF files runs on most operating systems and browsers, giving unsurpassed market reach. Support for PocketPC is an added bonus since that platform already has a Flash player.

Supported Flash features include font embedding, ActionScript components or movies, SOAP support, video streaming, and MP3 embedding. Several useful tools are provided including a SWF to XAML converter. This takes existing Flash graphics and turns them into XAML layout. The Illustrator SVG to XAML converter does the same for Adobe Illustrator.

The included server component automatically proxies external Web service calls. This works on any available IIS/ASP.NET architecture.

AFLAX Simplifies AJAX
AJAX is the Asynchronous Javascript and XML design pattern. You can build dynamic, rich, Internet applications connected via XML Web services. There is a relatively complex programming model that is deployed through DHTML. The browser must understand XML processing for this to work. The programmer must write JavaScript code that parses XML and binds data nodes to HTML element tags. Popular examples are http://maps.google.com and www.start.com, a browser-based RSS reader created by Microsoft research.

Data is loaded as needed through background XML Web service calls. The page does not refresh or round trip to the server. The user experience is much cleaner than traditional server-based Web page logic.

AFLAX, Asynchronous Flash and XML, delivers a similar result using the simpler programming model offered by C# and VB.NET. The user interface relies on XAML for vector graphics and Xamlon compilation creates a Flash .SWF. This format is ubiquitous and works in most any browser variant.

Xamlon provides a server-side proxy that works as a Web service connection point. Standard C# and VB.NET Web service calls use SOAP to transfer data from the proxy to the running Flash instance. There is basic support for datasets and control databinding. This greatly reduces the amount of code needed for dynamic data-driven applications.

The Xamlon Web site features two excellent AFLAX examples. One is an enterprise application with real-time stock updates pulled directly from Yahoo Finance and Fidelity. The other is a clone of Google Maps.

Building a Simple App - XAML
You can build a Xamlon interface using the XAML declarative model or procedural code. Start by opening a new project. Xamlon installation adds template folders to both VB and C# (see Figure 1).

More Stories By Bill Wolff

Bill Wolff is an independent consultant, trainer, and architect specializing in Microsoft development technologies. His company, Agility Systems, is based in the Philadelphia area. He ran the consulting firm Wolff Data Systems for 15 years and directed armies of consultants in the dot com world. Bill is founder and President of the philly.net user group, board member for INETA (Vice President, Speaker Bureau), and he is active in several other user communities. Bill was a contributing author to several books and articles and he currently writes for .NET Developer's Journal. His certifications include trainer, systems engineer, developer, and Microsoft MVP for VB.NET.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.