c# winform as3相互调用

C#主要代码:

首先要添加COM组件-Shockwave Flash Object

        //接收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;
        }
        //向flash发送信息
        private void sendToFlash_Click(object sender, EventArgs e)
        {
            this.axShockwaveFlash1.CallFunction("<invoke name=\"loadMsg\" returntype=\"xml\"><arguments><string>" +
                this.textBox1.Text + "</string><string>男<string></arguments></invoke>");
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.axShockwaveFlash1.Movie = Application.StartupPath + "/未命名-4.swf";
        }

flash文件主要代码as2.0:

接收有C#发送过来的消息

import flash.external.ExternalInterface;

ExternalInterface.addCallback("loadMsg",null,loadMsg);

function loadMsg(t1:String,t2:String):Void{
        txtName.text=t1;
  txtAge.text=t2;
 }

向C#窗体发送消息:

on(release)
{
 import flash.external.ExternalInterface;
 //trace("metadata received");
 ExternalInterface.call("loadMsg", txtName.text,txtAge.text);
}

C#与flash as3.0交互

as3.0 类文件编写 

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.txtsend.text);
        }
        
        public function setTxt(s:String,s2:String)
        {
            this.txtmsg.text=s+"-"+s2;
        }
    }
    
    
    } 

 C#代码的编写与as2.0通信的一样。

 

http://www.cnblogs.com/Xingsoft-555/archive/2010/05/09/1731221.html

c# winform as3相互调用

上一篇:抽丝剥茧设计模式- 责任链模式应用场景


下一篇:Ioc容器Autofac系列(2)-- asp.net mvc中整合autofac