Click here to Skip to main content
15,745,620 members
Articles / Web Development / ASP.NET
Posted 1 Jul 2005


45 bookmarked

Flash and .NET with FlashRemoting

Rate me:
Please Sign up or sign in to vote.
2.27/5 (9 votes)
1 Jul 20052 min read
Testing FlashRemoting with .NET.


This article explains how FlashRemoting works both in .NET and Flash. We use FlashRemoting for fast and secure communication with the database or other stored information and display it in a Flash movie. In this example we don't use any database, this is the simplest way to test it.

Using the code

First you have to install FlashRemoting from Macromedia and you have to have Macromedia Flash MX 2004 and ActionScript 2.0 installed.

Now we can start with the .NET code. First you have to start a new web application project in Visual Studio, and add the FlashRemoting server control as a new reference. You will find it in c:\inetpub\wwwroot\flashremoting\bin\flashgateway.dll.

Then you have to add this code in your Web.config under the system.web tag:

    <add name="GatewayController" 

Now we can start "coding". You have to make an inited page for the Flash so that Flash can connect to the .NET application. Just create a new page called "gateway.aspx".

To get the parameters in .NET application from Flash and then for sending the data to Flash, you have to add a server control into the page, so just make sure that your ASPX file looks like what is given below:

<%@ Register TagPrefix="Macromedia" 
    Namespace="FlashGateway" Assembly="flashgateway" %>
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" 
    Inherits="FlashRemotingTest.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
        <meta name="GENERATOR" 
          Content="Microsoft Visual Studio .NET 7.1">
        <meta name="CODE_LANGUAGE" Content="C#">
        <meta name="vs_defaultClientScript" 
        <meta name="vs_targetSchema" 
    <body MS_POSITIONING="GridLayout">
        <form id="Form1" method="post" runat="server">
            <MACROMEDIA:FLASH id="Flash1" Runat="Server" />

And now the Codebehind. For sending information to Flash from a .NET application you have use the server control named "flash1". In this sample, we will load a simple string in Flash:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace FlashRemotingTest
    /// <SUMMARY>
    /// Summary description for WebForm1.
    /// </SUMMARY>
    public class WebForm1 : System.Web.UI.Page {
        protected FlashGateway.Flash Flash1; 
        private void Page_Load(object sender, System.EventArgs e) {
            we check if the flash sended any data if it did go on. 
            if(Flash1.Params.Count >  0 )
                // we get the data from the flash servercomponent
                string sUsername = Flash1.Params[0].ToString();
                string sPassword = Flash1.Params[1].ToString();
                // we check if the username and password is correct
                if( sUsername == "user" && sPassword == "pass" )
                    // and we return the the answer
                    Flash1.Result = "Welcome Pelle Web !"; 
                    //return error code or text
                    Flash1.Result = "Wrong Username or password";

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
            // CODEGEN: This call is required by the ASP.NET 
            // Web Form Designer.
        /// <SUMMARY>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </SUMMARY>
        private void InitializeComponent()
            this.Load += new System.EventHandler(this.Page_Load);


Now we go for the Flash file. The Flash is a little special first when we add the inited function for connecting to the .NET application and it creates an object called "flashService" that you can use to connect to other classes.

Then you have to make three functions in ActionScript to call the logic in .NET.

// for Flash remoting
#include ""

// for flash debugging
#include ""

// init function
function init()
    if(this.inited != undefined)
        this.inited = true;
        //the url to the .NET application
        //makes a connection
        gatewayConnection = 
        // fixing the mapping of the application
        var services = "FlashRemotingTest";
        flashService = 
             gatewayConnection.getService(services, this);

//init the remoting        

//use the flashservice object and then the filename of 
//the .netpage in this case webform1.aspx looks like this
//remember that the function name webform1 have to be the 
//same name so in this case it chould be called login.        
function webform1(username, password){
    flashService.webform1(username, password);

//then make one function for the result of the funtion login 
//this is the function where the result will retun to
function webform1_Result(result){

// then make the last function for the remoting this 
// one is for the exception if it uccurs
function webform1_Status(error){

Now just add the function webform1() to the button. Download my code and you will get the Flash file and the .NET code.

Points of interest

When it works it works really cool and fast.


I will do one example using datasets directly into the Flash later on.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Written By
Architect Värderingsdata
Sweden Sweden
Systemdeveloper at Värderingsdata in Sweden

Comments and Discussions

QuestionPublishing flash remoting with Pin
deepak karma5-Dec-08 17:36
deepak karma5-Dec-08 17:36 
QuestionFunction calling in flash from page Flash Remoting with Pin
deepak karma18-Nov-08 17:44
deepak karma18-Nov-08 17:44 
QuestionFlash Remoting Pin
deepakkarma18-Nov-08 17:17
deepakkarma18-Nov-08 17:17 
QuestionSession State Pin
a_eqap22-May-07 22:19
a_eqap22-May-07 22:19 
Generalabout directory mapping Pin
meir_rivkin28-Feb-07 2:58
meir_rivkin28-Feb-07 2:58 
GeneralRe: about directory mapping Pin
OrakAManok16-Apr-07 23:04
OrakAManok16-Apr-07 23:04 
GeneralActionScript Issue Pin
callsaiprasad13-Jun-06 5:20
callsaiprasad13-Jun-06 5:20 
Generalmultiple functions Pin
ownersbox8-Jul-05 4:49
ownersbox8-Jul-05 4:49 
General... VC++.NET with Flashremoting Pin
FlyingDancer6-Jul-05 17:52
FlyingDancer6-Jul-05 17:52 
GeneralRe: ... VC++.NET with Flashremoting Pin
daniel_nilsson6-Jul-05 20:46
daniel_nilsson6-Jul-05 20:46 
GeneralRe: ... VC++.NET with Flashremoting Pin
FlyingDancer7-Jul-05 2:55
FlyingDancer7-Jul-05 2:55 
GeneralLink fixed Pin
daniel_nilsson3-Jul-05 10:23
daniel_nilsson3-Jul-05 10:23 
GeneralBad link to project code Pin
fwsouthern1-Jul-05 9:23
fwsouthern1-Jul-05 9:23 
GeneralRe: Bad link to project code Pin
M. Borsalino3-Jul-05 3:12
M. Borsalino3-Jul-05 3:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.