Click here to Skip to main content
Click here to Skip to main content

Sending Data from a Flash Movie to the Hosting C# Application

, 30 Sep 2005 CPOL
Rate this:
Please Sign up or sign in to vote.
An article showing how to send data from a Flash Movie to the hosting C# application, using FSCommand.

Introduction

In this article, we will see how we can send data from a Flash movie to the hosting C# application. I'll start by mentioning the requirements of creating this application.

Requirements

You will need the Macromedia Flash plug-in installed in your system, and you will also need Macromedia Flash software if you are required to create the Flash movie. Now we will move to the steps for creating the application.

Inside Macromedia Flash

Sending data to and from a Macromedia Flash movie to any hosting application will require a call to the FSCommand function. The FSCommand function takes two optional parameters which are the command and the parameters.

In this sample, I created three buttons and three circles inside the Macromedia Flash movie and converted them to symbols (will not dig in to details of creating the Flash movie).

In the on (press) event of all these six movie clip symbols, I inserted this code which differs according to the object. For example, I inserted the following code in the on(press) action script event of the blue button:

//
 on (press) {
    fscommand("Button","Blue");
}
//

and for the green circle, I used this code:

//
 on (press) {
    fscommand("Circule","Green");
}
//

However, you can use the FSCommand at any event inside the Flash movie, or even in the frame actions. To sum it up, you can use the FSCommand where you can write an action script Smile | :) .

Inside VS.NET

As mentioned before, you should have the Macromedia Flash Player (the OCX files registered in your system). So, now create a new C# Windows Forms project, and right click on the Toolbox while you are in the design view of the main form. Choose:

Choose Add/Remove Items, and you will get a window. Choose the COM Components tab and then check Shockwave Flash Object:

Now you will find the Shockwave Flash object added to your tool box. Drag and drop it in your form and resize it to match your Flash movie size. To choose the Flash movie, set the property Movie, and to choose whether to have it embedded inside your application or to reload it externally each time you run the application, set the property EmbedMovie. I prefer that you choose to set it to true, because not embedding it will require that you preserve the original path of the movie all the time (you may just put it next to the exe).

Now we are a step ahead to our destination. We now need to collect the data sent from the Flash movie. Select the Flash movie inside the form, and then in the property pane choose the events. You will find the event FSCommand, double click on it to create the needed event handler.

When the Flash movie sends its data via the FSCommand function, the C# program collects this data inside the AxShockwaveFlashObjects._IShockwaveFlashEvents_FSCommandEvent object which is defined in the event handler parameter e. So, to collect the sent command from the FSCommand Flash function, you will just need to use the e.command, and for the parameters, use e.args. However, before we write anything inside this function, drag a Label to the form and resize it to an appropriate size and name it lbl_Result. Now, moving back to the event handler of the FSCommand event, we want to tell the C# form which button or circle was clicked. So, we will need to add this code:

//code inside the event handeler of the fscommand
lbl_Result.Text="The "+e.args.ToString()+" "+e.command.ToString()+" was clicked";

and finally you will get the information that you clicked on the blue circle, for example:

You can use this simple interaction for more complex data transfer. I hope it was useful.;)

Using the code

There is almost no code in this project Big Grin | :-D , it's simple and small. You will just need to follow the above step by step explanation.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

HeldinBayoumy
Product Manager
Egypt Egypt
Agile Evangelist, Change Embracer and Success Facilitator. Project Manager and IT professional with 8+ years of leadership experience - http://www.hossamaldin.com
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
Questiondrag and drop a flash control in c# windows application. PingroupTricube3-Jun-13 2:42 
Questionsending data from c# to swf flash file. PinmemberBahramLavi13-May-13 13:06 
QuestionNot working on certain machines PinmemberTanmay_D3-Oct-11 6:42 
GeneralMy vote of 5 Pinmembermiladfozooni6-Feb-11 7:06 
GeneralAdd same functionality in window mobile Pinmembermohitisavailable13-Dec-10 0:45 
GeneralLoading a new form in vb from a swf file PinmemberVulcanriders18-Oct-09 8:54 
QuestionSending Data from a Hosting C# Application to the Flash Movie??? Pinmemberffrancoz11-Aug-09 8:14 
Jokethanks for all Pinmemberwikett28-Jul-09 6:57 
Questionhow can disable context menu of shockwave flash object? Pinmembermahdi_znt2-Jul-09 2:09 
QuestionFLA Pinmemberfagliaro30-Apr-09 2:23 
AnswerRe: FLA Pinmemberwusideng26-Jul-11 18:18 
GeneralSetVariable Pinmemberfagliaro30-Apr-09 1:52 
GeneralRE: Flash Pinmemberjberenguer1-Apr-09 12:45 
GeneralaxShockwaveFlash1.GetVariable does not work Pinmembercreep2374-Mar-09 16:55 
GeneralProperty does not shown Pinmemberwellage23-Sep-08 1:11 
QuestionInformation PinmemberMember 333319720-Jun-08 6:42 
AnswerRe: Information PinmvpJohn Simmons / outlaw programmer3-Jul-08 5:41 
GeneralRe: Information PinmemberMember 33331973-Jul-08 5:49 
GeneralRe: Information Pinmemberathor_a8-Sep-08 1:56 
GeneralThe movie dosen't work!!! Pinmemberamrhilmy24-Feb-08 13:19 
GeneralHelp Movie doesn't display Pinmemberlaura131617-May-07 14:46 
GeneralRe: Help Movie doesn't display Pinmemberamrhilmy24-Feb-08 13:21 
Questionshock wave flash object control dosenot work PinmemberMEDO_20082-Apr-07 11:11 
AnswerRe: shock wave flash object control dosenot work PinmemberHossam Aldin2-Apr-07 12:44 
GeneralRe: shock wave flash object control dosenot work PinmemberMEDO_20083-Apr-07 11:48 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141223.1 | Last Updated 30 Sep 2005
Article Copyright 2005 by HeldinBayoumy
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid