Interaction between flash and C # (simple button event)

Source: Internet
Author: User

 

1. Right-click the toolbar, select items, add COM components, and browse c: \ windows \ system32 \ macromed \ Flash to add the corresponding flash OCX.

2. Drag the Shockwave Flash Object Control in the toolbar to the interface.

3. Background setting code

Public form1 ()
{
Initializecomponent ();
This. axshockwaveflash1.movie = application. startuppath + "\ ee1e.swf ";
This. axshockwaveflash1.play ();
Axshockwaveflash1.flashcall + = new axshockwaveflashobjects. _ ishockwaveflashevents_flashcalleventhandler (flash_flashcall );
}

4. Add an as event in flash:

Select the button, right-click the action, and add the script as follows:

On (Release)
{
Import flash. External .*;
Externalinterface. Call ("test", "btn1 ");
}

Select another button and repeat the above operation to change "btn1" to "btn2"

5. Return to the C # program and add the following code in Step 1:

Void flash_flashcall (Object sender, axshockwaveflashobjects. _ ishockwaveflashevents_flashcallevent E)
{
String S = nodexml (E. Request. tostring () [0]. childnodes [0]. innertext. tostring ();

Switch (s)
{
Case "btn1 ":
This. label1.text = s;
Break;
Case "btn2 ":
This. label1.text = s;
Break;
Default:
Break;
}
Throw new exception ("Flash event error .");
}

Private xmlnodelist nodexml (string S)
{
Xmldocument Doc = new xmldocument ();
Doc. loadxml (s );
Xmlnodelist list = Doc. getelementsbytagname ("arguments ");
Return list;
}

Place a lable on the interface and click the button to view the result.

 

 

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.