Here I present one possibility of sending data from flash site to ASP.NET and how from ASP.NET respond to FLASH.
This tutorial is brought to you by NetroStar, a web design company.
Usually our flash applications are self-defended. But a few months ago we built the application which has user interface in flash and back end implemented in ASP.NET. And we started to think about the best way of communication between Flash and ASP.NET.
In this article I am going to present one possibility of sending data from flash site to ASP.NET and how from ASP.NET respond to FLASH. I will show you how to solve one simple problem connected with this issue. In flash site user enters his or her e-mail address. This data is sent to ASP.NET page, saved in database and then the result of this operation is redirected to flash site.
1. Sending data from Flash to ASP.NET site
To send e-mail address from flash to MailManager.aspx page I will use sendAndLoad object in Flash:
Syntax:
- myLoadVars .sendAndLoad( url , targetObject [ ,method ] )
Parameters:
- loadVarsObject – The LoadVars object to upload variables from.
- url – The URL to upload variables to.
- targetObject – The LoadVars object that receives the downloaded variables.
- method – The " GET " or " POST " method of the HTTP protocol.
This method posts variables in myLoadVars to given url. In ASP.NET page response is downloaded, parsed to string and the resulting variables are placed in the targetObject object. To do this in our flash, first we need to input textbox txtMail and label lblResult. Next we will read data from txtMail, send it to MailManager.aspx page and then the result will be shown in lblResult.
This is code in ActionScript:
2.Getting data in ASP.NET page and redirecting result
To catch sent mail from flash first we create a simple ASP.NET page: MailManager.aspx. Next in code behind we need void Page_load. In the body of function we will use QueryString to read sent data and after that, using Response object, we will direct result of operation:
Function bool saveMail(string mail) is used to save e-mail address in the database. To have a complete solution we should write a body of this method. For saving data we can use for example myGeneration – for more information go to tutorial "Introduction to myGeneration".
3. Summary
Of course this is only an example of how to use this way of communication between Flash and ASP.NET. To get a full solution you should create your own ErrorCodes and so you will able to tell your user why saving operation failed (for example: e-mail already exists in the database; timeout expired during sql connection, etc).
This tutorial was brought to you by NetroStar, a Miami-based global
web design company.