ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

ASP.Net and Flash Communication

Updated on October 13, 2009

Hello readers, I've covered in this article is just a small and simple overview of the world of Flash development with ASP.NET. I have recently designed a website, which thoroughly covers all of the Flash to ASP.NET communication methods mentioned in this article, as well as a step-by-step introduction to ASP.NET development with C# using Visual Studio.NET coolest IDE and Adobe Flash CS.

Step 1

Open Adobe Flash CS. Create a new document selecting Flash File (Action Script 2.0). You may be interested in Action Script 3 (AS3) but I choose Action Script 2 (AS2) for easier understand. Just step with me and I assure you, you will become a good Flash developer after reading this article. Now you will see a single tab namely ‘Untitled 1’ in the Adobe Flash. After saving the file ‘Untitled 1’ text will replace with your preferred filename. I named it ‘AspFlash.fla’. Remember FLA is a flash source file and your output movie will be SWF, which will need to be embedded in ASP.Net ASPX file later. Adobe Flash split-down with several window, do not confused. You do not need to know the all window features. Start with left called ‘Tools’, in the center top window called ‘Timeline’, next down window called ‘Scene’, next bottom window called ‘Properties’ and the right most window split-down with many window ‘Color’, ‘Align’, ‘Components’ and ‘Library’. Those entire windows can be switched on/off by ‘Window’ menu. Look at the ‘Scene’ window which will be your design area. From the ‘’Properties’ window you can change colors and size as per your requirements.

Step 2

Now add some component from the ‘Components’ window expand ‘User Interface’. Oh! lots of stuff. Drag only one ‘TextInput’ and one ‘Button’ on your ‘Scene’ window and align them correctly. Select ‘TextInput’ and put an instance name (e.g. TextInput1) from ‘Properties’ window. Without instance name, Action Script will not recognize any components. Do same for the ‘Button’ instance name (e.g. SendData) and from the ‘Parameters’ tab change ‘Button’ label (e.g. Send Data).

Step 3

Here we start out main coding part. Select ‘Layer 1’ from ‘Timeline’ window and press F9 (keyboard function key). You will see ‘Actions’ window, where you writes you’re AS code. Type or copy pest the following codes.

SendData.onPress = function() {

//Declare and Initialize variable

var send_lv:LoadVars = new LoadVars();

//Assigning value to parameter, like Asp.Net QueryString

send_lv.mydata = TextInput1.text;

//Sending data

send_lv.send('default.aspx', '_self', 'GET');

};

 

The LoadVars object is used for exchanging data between flash – server. The LoadVars object is capable of either sending data to the server for processing, loading data from the server, or sending data to the server and waiting for a response back from the server in one 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 doesn't require large amounts of data to be passed.

Send method sends the variables in the send_lv object to the specified URL. The string is posted to the URL using the HTTP

GET

method, so that ASP.Net easily read mydata variable in QueryString.

Step 4

Type or copy pest the following codes to read the 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 ‘AspFlash.swf’ file that was loaded with 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 File menu. Now we need to make the final SWF move and embed it to ASPX page. From File menu click ‘Publish Settings’ and you will see a new window containing three tabs (Formats, Flash and HTML). In the Formats tab check Flash and HTML types, so that you can get the SWF embedded code in HTML page. Now press button ‘Publish’ to build the final move. If there are no error occurred, flash will provide you to two files (e.g. ‘AspFlash.swf’ and ‘AspFlash.html’) in root folder where source file ‘AspFlash.fla’ located.

Step 6

Now start Visual Studio .Net (VS) and create a new website and name it ‘AspFlash’. VS create a default page namely ‘Default.aspx’. From solution explorer double click on ‘Default.aspx’ file to view Markup code (also called Inline code) like following.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>        
     </div>
    </form>
</body>
</html>

Now copy ‘AspFlash.swf’ and ‘AspFlash.html’ files in to your web root directory. I mean ASPX, SWF files should be located in same directory. Open ‘AspFlash.html’ file and copy the following lines and paste it inside <div> </div> tag of ‘Default.aspx’ file.

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"
width="550"
height="400"
id="AspFlash"
align="middle">
      <param name="allowScriptAccess" value="sameDomain"
/>
      <param name="allowFullScreen" value="false" />
      <param name="movie" value="AspFlash.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />   <embed src="AspFlash.swf" quality="high" bgcolor="#ffffff" width="550" height="400" name="AspFlash" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"
/>
      </object>

After pasting the above code little changed needed on ‘AspFlash.swf’ parameter like the following. Look at the line ‘AspFlash.swf?mydata='<% =Request["mydata"] %>'’ what we added. Flash read _url­ data with mydata which will be supplied by ASP.Net later.

<div>
        <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"
            width="550" height="400" id="AspFlash" align="middle">
            <param name="allowScriptAccess" value="sameDomain"
/>
            <param name="allowFullScreen" value="false" />
            <param name="movie" value="AspFlash.swf?mydata='<% =Request["mydata"] %>'" />
            <param name="quality" value="high" />
            <param name="bgcolor" value="#ffffff" />
            <embed src="AspFlash.swf?mydata='<% =Request["mydata"] %>'" quality="high" bgcolor="#ffffff"
                width="550" height="400" name="AspFlash" align="middle" allowscriptaccess="sameDomain"
                allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"
/>
        </object>
    </div>

Finally, add two ASP.net standard controls on ‘Default.aspx’ page (e.g. TextBox and Button). Change Button text property to ‘Send Data’. The full ‘Default.aspx’ will looks like the following.

<%@ Page
Language="C#"
AutoEventWireup="true"
CodeFile="Default.aspx.cs"
Inherits="_Default"
%>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"
            width="550" height="400" id="AspFlash" align="middle">
            <param name="allowScriptAccess" value="sameDomain"
/>
            <param name="allowFullScreen" value="false" />
            <param name="movie" value="AspFlash.swf?mydata='<% =Request["mydata"] %>'" />
            <param name="quality" value="high" />
            <param name="bgcolor" value="#ffffff" />
            <embed src="AspFlash.swf?mydata='<% =Request["mydata"] %>'" quality="high" bgcolor="#ffffff"
                width="550" height="400" name="AspFlash" align="middle" allowscriptaccess="sameDomain"
                allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"
/>
        </object>
    </div>
    <div>
        <asp:TextBox ID="textbox1" runat="server" Text=""></asp:TextBox>
        <asp:Button ID="button1" runat="server" Text="Send Data" OnClick="button1_Click">
        </asp:Button>
    </div>
    </form>
</body>
</html>

Step 7

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

protected void
Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
            if
(Request["mydata"] != null)
                textbox1.Text = Request["mydata"].ToString(); 
    }
    protected void button1_Click(object
sender, EventArgs e)
    {
        Response.Redirect("~/default.aspx?mydata=" +
textbox1.Text);
    }
 

Step 8

Now build the 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 ASPX ‘TextBox’ text changed with your Flash ‘TextInput’ text.

Same way type some text in ASPX ‘TextBox’ and click ‘Send Data’ Button to send ASPX data to Flash movie.

Enjoy the communication technique between ASP.Net and Flash. If need further assistance, feel free to contact me via email.

working

This website uses cookies

As a user in the EEA, your approval is needed on a few things. To provide a better website experience, hubpages.com uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: https://corp.maven.io/privacy-policy

Show Details
Necessary
HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
LoginThis is necessary to sign in to the HubPages Service.
Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
AkismetThis is used to detect comment spam. (Privacy Policy)
HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the googleapis.com or gstatic.com domains, for performance and efficiency reasons. (Privacy Policy)
Features
Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
MavenThis supports the Maven widget and search functionality. (Privacy Policy)
Marketing
Google AdSenseThis is an ad network. (Privacy Policy)
Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
Index ExchangeThis is an ad network. (Privacy Policy)
SovrnThis is an ad network. (Privacy Policy)
Facebook AdsThis is an ad network. (Privacy Policy)
Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
AppNexusThis is an ad network. (Privacy Policy)
OpenxThis is an ad network. (Privacy Policy)
Rubicon ProjectThis is an ad network. (Privacy Policy)
TripleLiftThis is an ad network. (Privacy Policy)
Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
Statistics
Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)
ClickscoThis is a data management platform studying reader behavior (Privacy Policy)