C# winform 与 flash as 的交互通讯

出处:

http://blog.csdn.net/lifesoftware/article/details/5389265

http://www.cnblogs.com/naiking/archive/2009/01/14/1375771.html

 

1、添加组件
  打开VS2008,工具-选择工具箱项-COM组件,勾选Shockwave Flash Object,确定。

2、将Flash组件放入窗体中
  将工具箱中的Shockwave Flash Object组件拖放到窗体中,设置其属性。

3、as代码

import flash.external.ExternalInterface;

// 向C#发送数据
if  (ExternalInterface.available)
{
    
var  strResult:String  =  ExternalInterface.call( " userValidate " , userid, password);
}


// 接收C#返回的结果
if  (ExternalInterface.available)
{
    ExternalInterface.addCallback(
" userValidate " , userValidate);
}

// 根据C#返回的结果处理
public  function  userValidate(str:String): void
{
    trace(str);
}

 

4、c#代码

public  mainForm()
{
    InitializeComponent();
    mainFlash.Movie 
=  Application.StartupPath  +   " \\swf\\DayBook.swf " ; // 设置flash地址
    mainFlash.Menu  =   false ;
    mainFlash.FlashCall 
+=   new  AxShockwaveFlashObjects._IShockwaveFlashEvents_FlashCallEventHandler(mainFlash_FlashCall);
}

private   void  mainFlash_FlashCall( object  sender, AxShockwaveFlashObjects._IShockwaveFlashEvents_FlashCallEvent e)
{
    XmlDocument document 
=   new  XmlDocument();
    document.LoadXml(e.request);
    XmlAttributeCollection attributes 
=  document.FirstChild.Attributes;

    
//  获取函数名
    String command  =  attributes.Item( 0 ).InnerText;

    
//  获取参数
    XmlNodeList list  =  document.GetElementsByTagName( " arguments " );
    
int  count  =  list[ 0 ].ChildNodes.Count; // 参数数量
     string [] arr_paras  =   new   string [count];
    
// 处理参数
     for  ( int  i  =   0 ; i  <  count;  ++ i)
    {
        arr_paras[i] 
=  list[ 0 ].ChildNodes[i].InnerText.ToString();
    }

    
switch  (command)
    {
       
case   " userValidate " :
             userValidate(arr_paras, 
" userValidate " );
             
break ;
       
case   " getPeopleList " :
             getPeopleList(arr_paras, 
" getPeopleList " );
             
break ;
    
     }
}

// C#传给Flash的值
private   void  callFunction( string  funName,  string  arg)
{
    
// funName:调用as中的函数
    
// arg:参数
    mainFlash.CallFunction( " <invoke name=\" "   +  funName  +   " \" returntype=\"xml\"><arguments><string> "   +  arg  +   " </string></arguments></invoke> " );
}

// 登录验证
public   void  userValidate( string [] arr_data,  string  functionName)
{
    
string  password  =  arr_data[ 1 ];
    password 
=  OperClass.Encrypt(password,  1 );
    
string  sql  =   " select id,username from users where state='0' and userid= "   +  OperClass.str(arr_data[ 0 ])  +   "  and password= "   +  OperClass.str(password);
    DataSet ds 
=  dbc.ExecuteSqlDsForAccess(sql,  " info " );

    
string  result  =   "" ;
    
if  (ds  !=   null   &&  ds.Tables[ " info " ].Rows.Count  >   0 )
    {
        result 
=  ds.Tables[ " info " ].Rows[ 0 ][ " id " ].ToString()  +   " "   +  ds.Tables[ " info " ].Rows[ 0 ][ " username " ].ToString();
    }
    
else
    {
        result 
=   " -1 " ;
    }
    callFunction(functionName, result);
}

 

转载于:https://www.cnblogs.com/flycantus/archive/2011/08/24/2151825.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值