C # communication with Flash

Source: Internet
Author: User
C # interaction with Flash as2.0

 

C # Main Code:

First, add the COM component-Shockwave Flash Object.

// Receives the information sent from flash.
Private void axshockwaveflash1_flashcall (Object sender, axshockwaveflashobjects. _ ishockwaveflashevents_flashcallevent E)
{
Xmldocument document = new xmldocument ();
Document. loadxml (E. request );

Xmlnodelist list = Document. getelementsbytagname ("arguments ");
Loadtitleandauthor (convert. tostring (list [0]. firstchild. innertext), convert. tostring (list [0]. childnodes [1]. innertext ));
}
Public void loadtitleandauthor (String title, string author)
{
Textbox2.text = title + "," + author;
}
// Send messages to flash
Private void sendtoflash_click (Object sender, eventargs E)
{
This. axshockwaveflash1.callfunction ("<invoke name = \" loadmsg \ "returntype = \" XML \ "> <arguments> <string>" +
This. textbox1.text + "</string> <string> male <string> </arguments> </invoke> ");
}

Private void form1_load (Object sender, eventargs E)
{
This. axshockwaveflash1.movie = application. startuppath + "/unnamed -4.swf ";
}

The main code of the Flash file is as2.0:

Receive messages sent from C #

Import flash. External. externalinterface;

Externalinterface. addcallback ("loadmsg", null, loadmsg );

Function loadmsg (T1: String, T2: string): void {
Txtname. Text = T1;
Txtage. Text = t2;
}

Send messages to C # forms:

On (Release)
{
Import flash. External. externalinterface;
// Trace ("metadata initialized ed ");
Externalinterface. Call ("loadmsg", txtname. Text, txtage. Text );
}

C # interaction with Flash as3.0

As3.0 file writing

Package {
Import flash. display .*;
Import flash. display. movieclip;
Import flash. Events. event;
Import flash. Events. mouseevent;
Import flash. utils. getdefinitionbyname;
Import flash. External. externalinterface;
Import flash. Text .*;

Public class CLAS extends movieclip
{
Public Function CLAS ()
{
Btnsend. addeventlistener (mouseevent. Click, onclick );
Externalinterface. addcallback ("settxt", settxt );
}

Public Function onclick (EVT: mouseevent ){
Externalinterface. Call ("totxt", this.txt send. Text );
}

Public Function settxt (S: String, S2: string)
{
This.txt MSG. Text = S + "-" + S2;
}
}


}

C # code compilation is the same as as2.0 communication.

 

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.