C # development of Flash programs

Source: Internet
Author: User

You can try the following keywords to search for other materials
Keywords (C #, Flash, winform, Flash Embedded C #, flash development UI)

To embed flash in the C # winform program, the OCX control of Flash is directly referenced.
Then you need to use the "COM component" Shockwave Flash Object. However, the "flash. ocx" control cannot be directly found in the "COM components" window ..
You need to manually add the toolkit, select "Tools"> "Custom toolkit" from the menu, open the "Custom toolkit" window, and click "Browse" in "COM components, then select "C: // WINNT (Windows) // system32 // macromedflashswflash. OCX control. After confirmation, you can see two new controls in the toolbox: "flashfactory" and "shockwaveflash ".

Add control note
I have installed both the "XP system" and flash 8 and Flash 9. shockwaveflash is under the "C:/Windows/system32/macromed/flash/" Directory (I used "flash9d. OCX ")

When you find that your shockwaveflash program prompts you "not registered", you may lack the "Microsoft Multimedia Control, version 6.0" control. You can add this control to the "toolbox" first. This control is available in "C:/Windows/system32/mci32.ocx". If not, you can download

Now we can embed a flash into the program.

Movie: storage address of Flash
Embedmovie: whether to embed data into program resources.


After the initializecomponent (); control is loaded, flashbox_ui.movie = application. startuppath + "// flashplayer.swf"; connects to the embedded SWF File

The form1.cs file is as follows:

Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. text;
Using system. Windows. forms;

Namespace flashshell2
{
Public partial class form1: Form
{
Public form1 ()
{
Initializecomponent ();
Flashbox_ui.movie = application. startuppath + "// flashplayer.swf ";
}
}
}
--------------------------------- Flash C # communication --------------------------------------

In flash, you can use the fscommand function to communicate with the hosting app. This function has two parameters:

Command: command name
Parameters: Parameters

Example:

On (Press ){
Fscommand ("circule", "green ");
}

In C #, process the fscommand event of the Flash Object.
If the eventargs of the event processing function is E, the corresponding relationship is as follows:

E. Command-> command parameter when fscommand is called in Flash;
E. ARGs-> the arguments parameter when fscommand is called in flash.

The setvariable method is used to transmit values to flash in C:

Axshockwaveflash1.setvariable ("variablename", "valueasstring ");

Corresponding, there is a getvariable method to get the variable value in flash.

Only one fscommand parameter can be passed, so its function has some limitations. When you need to pass multiple parameters, the caller needs to concatenate the parameter values with strings and then unbind them again. This method makes complex value passing ugly.

However, in addition to fscommand, we also have another way to communicate with flash by Using Flash Player 8 External API.
Http://www.codeproject.com/cs/media/flashexternalapi.asp)

The external API can be used to implement two-way calls of ActionScript and C. The advantage is that the parameters and returned values are passed through an XML document each time you call them, which is much better than the fscommand function. Of course, in C #, we also need to declare the ing between external function implementations.

Code snippet:
Declare the callback function provided to the hosting application in Flash ActionScript:

Import flash. External. externalinterface;
Externalinterface. addcallback ("loadandplayvideo", null, loadandplayvideo );

When flash is called in C:

Flashplayer. callfunction ("<invoke" +
"Name =/" loadandplayvideo/"returntype =/" XML/">
<Arguments> <string> "+ filedialog. filename +
"</String> </arguments> </invoke> ");

Call the C # function in ActionScript:

Externalinterface. Call ("resizeplayer ",
Videoplayer. Metadata. Width, videoplayer. Metadata. Height );

Declare the function called by flash in C:

Flashplayer. flashcall + =
New _ ishockwaveflashevents_flashcalleventhandler (flashplayer_flashcall );

Here, we can see that the communication between C # And flash is quite convenient.

In addition, I found some other good articles related to flash by the way:

Flash and. Net with flashremoting
Http://www.codeproject.com/aspnet/FlashRemoting.asp

Multiple File Upload with progress bar using flash and ASP. NET
Http://www.codeproject.com/aspnet/FlashUpload.asp

Flash GUI for your EXE using minimalistic approach (C ++)
Http://www.codeproject.com/useritems/FlashGui.asp

C # callback function

Axshockwaveflash. flashcall + =
New _ ishockwaveflashevents_flashcalleventhandler (setnum );

Public void setnum (Object sender, _ ishockwaveflashevents_flashcallevent E)
{
// Obtain the parameter list
Arraylist paralist = getparalist (E. request );
}

Public arraylist getparalist (string paralistxml)
{
Xmldocument Doc = new xmldocument ();
Doc. loadxml (paralistxml );

Xmlnodelist parenodelist = Doc. getelementsbytagname ("string ");

Arraylist paralist = new arraylist ();
Foreach (xmlnode node in parenodelist)
{
Paralist. Add (node. innertext );
}

Return paralist;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.