Welcome!

.NET Authors: Liz McMillan, Peter Silva, Yakov Werde, Matthew Pollicove , Kevin Benedict

Related Topics: .NET

.NET: Article

The Xamlon Story

.NET code + XAML markup = Flash SWF

An SWF Application provides standard controls such as buttons, labels, and textboxes. An SWF Project is for coded Flash API applications. The Solution Explorer lists the files generated by the template (see Figure 2).

App.xaml is used for general layout and graphic objects. Assemblyinfo.vb has the standard .NET compilation directives. File1.vb is a class file that imports several referenced assemblies (see Figure 3).

These assemblies contain the Xamlon bytecode libraries that match Flash primitives. There must be references to these assemblies in the project (see Figure 4).

The XamlControls library contains controls that are familiar to a Windows Forms or ASP.Net developer. Details can be viewed in the object browser, as shown in Figure 5.

The SwfNative library contains objects that map directly to Flash primitives. One of the most used objects is a MovieClip (see figure 6).

The containing window is referred to as the Canvas. There are multiple layers that render on top of each other. Setting the Z-order produces a layered interface. The Desktop object is used in procedural code to create controls and add them to a layer:


Private Shared Sub CreateSampleWindow()
' create window
Dim window As Window = New Window(200, 80)
window.Text = "Reader Survey"
window.X = 80
window.Y = 10
' add a button
b1 = New Xamlon.Swf.Controls. Button(75, 30)
b1.X = 10
b1.Y = 10
b1.Text = "What do you read?"
' add to window
window.AddChild(b1)
' add window to desktop
desktop.AddChild(window)
' show window
window.Show
End Sub
Running this sample creates the window shown in Figure 7 .

The size of the window is driven by the XAML declarative markup. The Canvas object has a size:


<?xml version="1.0"?>
<!-- The width and height of your swf file is set from these -->
<Canvas Width="360" Height="240">
<Canvas.Resources>
</Canvas.Resources>
</Canvas>
Button events are coded in typical .NET fashion, including an event handler with one parameter.

Shared Sub b1_Click(ByVal sender As System.Object) Handles b1.Click
Console.WriteLine(".NET Developers Journal")
End Sub
This requires some initial set-up. The MovieClip object is used to create a TextField called Con-sole. Writing Console displays the text string at the desired location.

Public Shared Function CreateConsole()
consoleField = MovieClip.Root. CreateTextField(10, 100, 290, 390, -1)
consoleField.TextColor = &H333333
consoleField.Variable = "Console"
End Function
Pressing the button displays the console text shown in Figure 8.

The project folder contains the solution file, project file, XAML markup, vb class file, and user options(see Figure 9).

The bin folder gets a little busy. There are some resource files, a series of intermediate IL and SWF files, and the compiled exe and swf. The batch file is used for post processing of the compiled .NET MSIL. It has a call to the CWSF compiler.

The HTML file is a testbed for viewing the SWF in a browser. Copy this file, the SWF, and any associated image or movie clips to a Web site. Review the HTML code and copy to your Web application as needed. Here is a sample of the object tag definition:


<object width="100%" height="100%"
classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
codebase-"http://fpdownload.macromedia.com/pub/shockwave/cabs/

flash/swflash.cab#version
<param name-"allowScriptAccess"
value-"sameDomain" />
<param name="movie" value="SwfApplication3.swf" />
<embed width="100%" height="100%"
src="SwfApplication3.swf" allow-ScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>

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.