Create a “Hello World” Application with GOA WinForms for Flash
July 6th, 2007Introduction
This QuickStart Topic describes how to create a basic "Hello World" project using GOA WinForms for Flash.
Prerequisites:
- Adobe Flash Player (version 9.0 recommended)
- Microsoft Visual Studio 2005.
- GOA WinForms for Flash (available from the NETiKA Technologies site)
Creating a GOA Project Using Visual Studio
- Start Visual Studio 2005.
- On the File menu, click New Project.
- In the New Project" dialog box, under the "GOA Projects" folder, choose GOA Application.
- Name your application "HelloWorld" and click OK.
A new Visual Studio project is created.
Open the Form1.ccs file that has been automatically generated. In this file, you can watch the code of a "almost standard" .NET Windows Form holding a button.
Compile and run the HelloWorld application
- On the Debug menu, click Start.
- A dialog box asking if you would like to build the project is displayed. Click Yes to build the project.
- The application starts. A form holding a button is displayed.
Here is what has happened when you have started debugging the application:
- The code of the application has been compiled using the GOA compiler.
- A swf file ("executable" Flash file) has been generated.
- The swf file has been loaded inside the Visual Studio Internal Web Browser.
If you go to the bin\Debug subdirectory of your project using the Windows Explorer you will see two files:
- The HelloWorld.swf file is the swf file that has been generated by the compiler from the C# code of the project.
- The HelloWorld.swf.html page is a basic html page that has been generated to load the HelloWorld.swf file.
Note that the project has been compiled using the GOA compiler and not the .NET C# compiler. The GOA compiler allows to generate a swf ("executable" Flash file) from C# code.
Also note the ccs extension of the Form1.ccs file. This is the default C# file extension for GOA.
The swf file that you have just compiled can be run under Flash Player version 7 or above. Nevertheless, it is recommended to target Flash Player version 9 or above.
- In the Solution Explorer Right Click your project
- In the drop down menu, click the Properties item
- On the right of the Property Pages dialog box, select the Build node under the Configuration Properties node
- Change the Platform Target value to Flash 9 or higher
- Click OK
Now that your platform target is Flash 9, the swf will run a lot faster but it will not be compatible with the earlier versions of the Flash Player.
Adding references to the project
As GOA WinForms for Flash does not use the .NET C# compiler, it also does not use the .NET assemblies. Instead GOA is shipped with its own libraries that provide a large subset of the Microsoft .NET Framework.
- In the Solution Explorer expand the References node
- Right Click the References node and click the Add Reference... item
- In the Add Reference dialog box, click the Libraries tab. This tab displays a list of the libraries provided by GOA. Currently, your project references System.Windows.Forms, System.Drawing and System libraries. These libraries provides GOA basic features and they include a large set of controls. More advanced controls are provided by the GOAGrid and GOAToolkit libraries.
- Double click a library in the list if you would like to reference it.
- Click the Cancel button. We will not need other references in our sample.
Add a button and a label to the HelloWorldForm
Now that we understand the basics of GOA WinForms for Flash, we can write some code in the HelloWorldForm class to create our Hello World application.
Note that we are coding our project in a standard way as if we were creating a .NET Windows Forms desktop application.
We are adding a label at the top of the form and moving the button at the bottom. When the user will click on the button, the label will display the "Hello World" text.
- First let's add a label to the form and move the button at
the bottom of the form. The code that follow is very
close to any code generated by the Visual Studio Windows Forms
Designer:
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; namespace HelloWorld { public class Form1 : System.Windows.Forms.Form { private Button button1; private Label label1; private System.ComponentModel.Container components = null; public Form1() { InitializeComponent(); } protected override void Dispose( bool disposing ) { if( disposing ) { if (components !=null) { components.Dispose(); } } base.Dispose( disposing ); } private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); this.SuspendLayout(); this.button1.Location = new System.Drawing.Point(84, 140); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(104, 36); this.button1.Text = "Click Me"; this.label1.Location = new System.Drawing.Point(40, 44); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(200, 44); this.Controls.Add(this.label1); this.Controls.Add(this.button1); this.ResumeLayout(false); } static void Main() { Application.Run( new Form1() ); } } }
- We also need to add an event handler to manage the button click event.
Add the following line in the InitializeComponent method of the form:
And, of course, we also have to add the method that will set the text of the labelvoid button1_Click( object sender, EventArgs e ) { this.label1.Text = "Hello World"; }
Before, starting the application, let's change the settings in order to start it in an external browser.
- In the Solution Explorer, Right Click your project
- In the drop down menu, click the Properties item
- On the right of the Property Pages dialog box, select the Debugging node under the Configuration Properties node
- Change the Start Program Type value to Internet Explorer
- Click OK
Now, you can start your application.