Click here to Skip to main content
15,881,044 members
Articles / Programming Languages / C#
Article

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

Rate me:
Please Sign up or sign in to vote.
4.87/5 (26 votes)
30 Sep 2005CPOL3 min read 208.9K   5.1K   77   47
An article showing how to send data from a Flash Movie to the hosting C# application, using FSCommand.

Image 1

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.

Image 2

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).

Image 3

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 :).

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:

Image 4

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

Image 5

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).

Image 6

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.

Image 7

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:

C#
//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:

Image 8

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 :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)


Written By
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

Comments and Discussions

 
GeneralRe: Crossplatform Pin
HeldinBayoumy27-Apr-06 11:07
professionalHeldinBayoumy27-Apr-06 11:07 
GeneralGreat and simple ! Pin
JetDraft24-Apr-06 22:06
JetDraft24-Apr-06 22:06 
Questionhow do I do the opposite? Pin
Green Fuze20-Apr-06 5:26
Green Fuze20-Apr-06 5:26 
AnswerRe: how do I do the opposite? Pin
michbex27-Apr-06 9:07
michbex27-Apr-06 9:07 
GeneralMore Complex Pin
StressBall2-Jan-06 15:49
StressBall2-Jan-06 15:49 
GeneralTransparent Pin
lovewindy19-Oct-05 18:49
lovewindy19-Oct-05 18:49 
GeneralRe: Transparent Pin
HeldinBayoumy21-Oct-05 11:03
professionalHeldinBayoumy21-Oct-05 11:03 
GeneralRe: Transparent Pin
lovewindy23-Oct-05 16:56
lovewindy23-Oct-05 16:56 
i want to know winform,
thanks all the same!!!
GeneralRe: Transparent Pin
Pascalsz9-Dec-05 3:57
Pascalsz9-Dec-05 3:57 
AnswerRe: Transparent Pin
athor_a8-Sep-08 5:04
athor_a8-Sep-08 5:04 
GeneralNot working Pin
Jitu999-Oct-05 14:58
Jitu999-Oct-05 14:58 
GeneralRe: Not working Pin
HeldinBayoumy9-Oct-05 23:24
professionalHeldinBayoumy9-Oct-05 23:24 
GeneralRe: Not working - Working Now Pin
Jitu9910-Oct-05 5:22
Jitu9910-Oct-05 5:22 
GeneralRe: Not working - Working Now Pin
hanafi315-Oct-05 7:06
hanafi315-Oct-05 7:06 
GeneralRe: Not working - Working Now Pin
Member 333319720-Jun-08 6:02
Member 333319720-Jun-08 6:02 
GeneralRe: Not working - Working Now Pin
hanafi315-Oct-05 7:09
hanafi315-Oct-05 7:09 
GeneralRe: Not working - Working Now Pin
HeldinBayoumy15-Oct-05 12:41
professionalHeldinBayoumy15-Oct-05 12:41 

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.