码迷,mamicode.com
首页 > Windows程序 > 详细

c# winform as3相互调用

时间:2014-10-27 17:04:03      阅读:452      评论:0      收藏:0      [点我收藏+]

标签:des   winform   blog   http   io   os   ar   for   sp   

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相互调用

标签:des   winform   blog   http   io   os   ar   for   sp   

原文地址:http://www.cnblogs.com/lvcha/p/4054314.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!