In this article, you will learn the world of Flash development with ASP.NET. I recently designed a website, which thoroughly covers all the Flash to ASP.NET communication methods mentioned in this article, as well as a step-by-step introduction to developing ASP.NET with C # using Visual Studio.NET, the best SDI. and Adobe Flash CS.

Step 1

Open Adobe Flash CS. Create a new document by selecting Flash File (Action Script 2.0). You may be interested in Action Script 3 (AS3), but I choose Action Script 2 (AS2) to understand it better. Come to me and I assure you that you will become a good Flash developer after reading this article. You will now see a single tab called ‘Untitled 1’ in Adobe Flash. After saving the file, the text ‘Untitled 1’ will be replaced with your preferred file name. I called it ‘AspFlash.fla’. Remember that FLA is a flash source file and your output movie will be SWF, which will need to be embedded in the ASP.Net ASPX file later.

Adobe Flash divided with multiple windows, do not confuse. You do not need to know all the functions of the window. Start with the left one called ‘Tools’, in the upper middle window called ‘Timeline’, the next lower window called ‘Scene’, the next lower window called ‘Properties’ and the rightmost window divided down with many ‘Color’, ‘Align’, ‘Components’ and ‘Library’ windows. Those entire windows can be enabled / disabled via the “Window” menu. Look at the ‘Scene’ window which will be your design area. From the ” Properties’ window you can change the colors and size according to your requirements.

Step 2

Now add some component from the ‘Components’ window expand ‘User Interface’. Oh! a lot of things. Drag just a ‘TextInput’ and a ‘Button’ into your ‘Scene’ window and align them correctly. Select ‘TextInput’ and put an instance name (eg TextInput1) from the ‘Properties’ window. Without the instance name, Action Script will not recognize any components. Do the same with the instance name ‘Button’ (for example SendData) and from the ‘Parameters’ tab change the label ‘Button’ (for example Send Data).

Step 3

Here we start with the main part of coding. Select ‘Layer 1’ in the ‘Timeline’ window and press F9 (keyboard function key). You will see the ‘Actions’ window, where you type your AS code. Write or copy the following codes.

SendData.onPress = function () {

// Declare and initialize variable

var send_lv: LoadVars = new LoadVars ();

// Assign value to parameter, such as Asp.Net QueryString

send_lv.mydata = TextInput1.text;

// Sending data

send_lv.send (‘default.aspx’, ‘_self’, ‘GET’);

};

The LoadVars object is used to exchange data between flash – server. The LoadVars object is capable of sending data to the server for processing, loading data from the server or sending data to the server, and waiting for a response from the server in an operation. The LoadVars object uses name-value pairs to exchange data between the client and the server. The LoadVars object is best used in a scenario that requires two-way communication between the Flash movie and server-side logic, but does not require large amounts of data to be passed.

The send method sends the variables of the send_lv object to the specified URL. The string is posted to the URL using the HTTP GET method, so ASP.Net easily reads the variable mydata in the QueryString.

Step 4

Write or copy the following codes to read QueryString in Flash – Action Script 2. In Action Script 2 there are no methods like ASP.Net provides, so I wrote the following codes to get QueryString from URL. The _url method returns the URL of the file ‘AspFlash.swf’ that was loaded with the ASPX page.

// Reading QuaryString

myURL = this._url;

myPos = myURL.lastIndexOf (“?”);

if (myPos> 0) {

var myRawParam = myURL.substring (myPos + length (‘mydata =’) + 1, myURL.length);

myParam = myRawParam.toString (). split (“‘”). join (“”);

if (myParam! = undefined) {

TextInput1.text = myParam;}

Step 5

Save your file from the File menu. Now we have to do the final SWF move and embed it in the ASPX page. From the File menu, click on ‘Publish Settings’ and you will see a new window containing three tabs (Formats, Flash and HTML). On the Formats tab, check Flash and HTML types, so you can get the SWF code embedded in the HTML page. Now hit the ‘Publish’ button to build the final move. If no error occurs, flash will provide you with two files (for example, ‘AspFlash.swf’ and ‘AspFlash.HTML’) in the root folder where the source file ‘AspFlash.fla’ is located.

Step 6

Now start Visual Studio.Net (VS) and create a new website and name it ‘AspFlash’. VS creates a default page called ‘Default.aspx’. From solution explorer, double click the ‘Default.aspx’ file to view the markup code (also called inline code) as follows.

Now copy the files ‘AspFlash.swf’ and ‘AspFlash.HTML’ to your web root directory. I mean ASPX, the SWF files must be located in the same directory. Open the file ‘AspFlash.HTML’ and copy the entire tag of the ‘object’ and paste it inside the tag of the file ‘Default.aspx’.

After pasting the above code, little changes are needed to the ‘AspFlash.swf’ parameter like the following. Look at the line ‘AspFlash.swf? Mydata = ” ‘what we add. Flash reads the _url data with mydata which will be provided by ASP.Net later.

Finally add two standard ASP.net controls on page ‘Default.aspx’ i.e TextBox and Button. Change the button’s text property to ‘Submit Data’.

Step 7

In this step, you need to open the ‘Default.cs’ file by clicking ‘View Code’ pointing to ‘Default.aspx’ from VS Solution Explorer. By default VS added → Load event procedure. You need to add some text about the UniesLoad event procedure along with the button1_click event procedure like the following.

protected empty représentationLoad (object sender, EventArgs e)

{if (! IsPostBack)

yes (Request[“mydata”]! = null)

textbox1.Text = Request[“mydata”].String ();}

protected empty button1_Click (sender of object, EventArgs e)

{Response.Redirect (“~ / default.aspx? Mydata =” + textbox1.Text);}

Step 8

Now create website using F5 (keyboard function key) and type some text in Flash movie and click ‘Send data’ to send Flash data to ASPX page. You will see the ASPX text ‘TextBox’ changed with your Flash text ‘TextInput’.

In the same way, write a text in ASPX ‘TextBox’ and click the ‘Send Data’ button to send ASPX data to Flash movie. Enjoy technical communication between ASP.Net and Flash. If you need further assistance, please feel free to contact me by email.