FLASH与ASP.NET通讯[Flash | CS3 | ActionScript | ASP.NET | FluorineFx ]

简介:

1.下载安装FluorineFx,新建一个FluorineFx示例项目:

     

2.新建项目之后会生成很多文件,可以先浏览一下,尤其是Web.config文件,然后在App_Code下编写测试连接类:

     Test.cs

using  System;
using  System.Data;
using  System.Configuration;
using  System.Web;
using  System.Web.Security;
using  System.Web.UI;
using  System.Web.UI.WebControls;
using  System.Web.UI.WebControls.WebParts;
using  System.Web.UI.HtmlControls;

///   <summary>
///  Test 的摘要说明
///   </summary>
public   class  Test
{
    
public  Test()
    {
        
//
        
//  TODO: 在此处添加构造函数逻辑
        
//
    }

    
///   <summary>
    
///  
    
///   </summary>
    
///   <param name="sName"></param>
    
///   <returns></returns>
     public   string  hello( string  sName)
    {
        
return   " hello, "   +  sName;
    }
}

3.修改配置文件Web.config,这里注意了,大家就不要走弯路了,用默认的配置是连不上的,我是后来找它自带的例子的时候才找到可用的配置文件的,如下,直接覆盖就行。

<? xml version="1.0" ?>
<!--  
    Note: As an alternative to hand editing this file you can use the 
    web admin tool to configure settings for your application. Use
    the Website->Asp.Net Configuration option in Visual Studio.
    A full list of settings and comments can be found in 
    machine.config.comments usually located in 
    \Windows\Microsoft.Net\Framework\v2.x\Config 
-->
< configuration  xmlns ="http://schemas.microsoft.com/.NetConfiguration/v2.0" >
    
< configSections >
        
< sectionGroup  name ="fluorinefx" >
            
< section  name ="settings"  type ="FluorineFx.Configuration.XmlConfigurator, FluorineFx"  requirePermission ="false" />
        
</ sectionGroup >
    
</ configSections >
    
< fluorinefx >
        
< settings >
            
<!--  value="browse|access"  -->
            
< remotingServiceAttribute > browse </ remotingServiceAttribute >
        
</ settings >
    
</ fluorinefx >
    
< connectionStrings />
    
< system.web >
        
< httpModules >
            
< add  name ="FluorineGateway"  type ="FluorineFx.FluorineGateway, FluorineFx" />
        
</ httpModules >
        
< compilation  debug ="true" >
            
< assemblies >
                
< add  assembly ="System.Messaging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /></ assemblies ></ compilation >
        
< authentication  mode ="None" />
    
</ system.web >
</ configuration >

4.编写flash的CS文件,这里是用的NetConnection进行连接的,cs代码如下:

     RemotingConnection.as

package
{
    
import  flash.net.NetConnection;
    
import  flash.net.ObjectEncoding;
    
import  flash.net.URLLoader;
    
import  flash.net.URLRequest;
    
import  flash.events.Event;
    
import  flash.system.Security;
    
    
public   class  RemotingConnection  extends  NetConnection
    {
        
public  function RemotingConnection(gatewayUrl:String)
        {
            
// 设置通信权限
            Security.allowDomain(gatewayUrl);
            
// 设置数据格式
             this .objectEncoding  =  ObjectEncoding.AMF0;
            
// 连接网关
             this .connect(gatewayUrl);
        }
    }
}

     ConnectionASPNET.as

package
{
    
import  flash.display.Sprite;
    
import  RemotingConnection;
    
import  flash.net.Responder;
    
    
public   class  ConnectionASPNET  extends  Sprite
    {
        
public  var gateway:RemotingConnection;
        
public  var responder:Responder;
        
        
public  function ConnectionASPNET()
        {
            
// 连接网关
            
// http://localhost :1968/Gateway.aspx
            
// http://localhost :1968/FluorineFx/GateWay.aspx
            gateway  =   new  RemotingConnection( " http://localhost:1968/Gateway.aspx " );
            
// 调用类
            gateway.call( " Test.hello " , new  Responder(onResult,onFault), " lalo " );
        }
        
        
/** *************************
        * 返回成功
        *
*/
        
public  function onResult(resultt:Array): void
        {
            trace(resultt);
        }
        
        
/** *************************
        * 返回失败
        *
*/
        
public  function onFault(fault:String): void
        {
            trace(fault);
        }
    }
}

     说明:

               a)as调用的时候用的是类的全限定名加方法名称,很明显ASP.NET这边是要用反射来找这个类了。

               b) new Responder 第二个参数可以设置为null,表示不接受错误返回,默认也是null

               c) call 方法最后的参数是不定的,也就是你传的参数,可以不传,也可以传1个、2个、3个......

5.走到这一步基本上没有什么问题了,能够通讯了,但是调用起来有点麻烦,因为不是阻塞式的,不能直接调用就能拿到返回值,用了接受返回值的回调函数onResult,咋办?我的办法就是用一个变量保存验证前后的状态,像这样:

//null 未完成通讯
public  var CheckFlag:String   =   null ;

     在接受的地方把代码改成

CheckFlag = resultt;

     接受结果时用Timer来阻塞当前线程来等待服务器返回数据,如下

var oneMinuteTimer:Timer  =   new  Timer( 500 3 );
            oneMinuteTimer.start();
            oneMinuteTimer.addEventListener(TimerEvent.TIMER,timerevent);
            function timerevent(e:TimerEvent) {
                
if (asp.CheckFlag  ==   null )
                {
                    
// 说明还没有通讯完毕,继续等待
                }
                
else
                {
                    
// 显示到swf的文本框
                    tbShowInfo.text  =  asp.CheckFlag.toString();
                    
// 终止Timer
                    oneMinuteTimer.removeEventListener(TimerEvent.TIMER,timerevent);
                }
            }

 本文转自博客园农民伯伯的博客,原文链接:FLASH与ASP.NET通讯[Flash | CS3 | ActionScript | ASP.NET | FluorineFx ],如需转载请自行联系原博主。

目录
相关文章
|
16天前
|
开发框架 JSON .NET
ASP.NET Core 标识(Identity)框架系列(三):在 ASP.NET Core Web API 项目中使用标识(Identity)框架进行身份验证
ASP.NET Core 标识(Identity)框架系列(三):在 ASP.NET Core Web API 项目中使用标识(Identity)框架进行身份验证
|
7天前
|
开发框架 .NET 开发工具
【Azure 应用服务】App Service 的.NET Version选择为.NET6,是否可以同时支持运行ASP.NET V4.8的应用呢?
【Azure 应用服务】App Service 的.NET Version选择为.NET6,是否可以同时支持运行ASP.NET V4.8的应用呢?
|
2月前
|
开发框架 搜索推荐 前端开发
【.NET全栈】ASP.NET开发Web应用——Web部件技术
【.NET全栈】ASP.NET开发Web应用——Web部件技术
|
16天前
|
开发框架 .NET 数据库连接
ASP.NET Core 标识(Identity)框架系列(一):如何使用 ASP.NET Core 标识(Identity)框架创建用户和角色?
ASP.NET Core 标识(Identity)框架系列(一):如何使用 ASP.NET Core 标识(Identity)框架创建用户和角色?
|
3月前
|
Linux C# C++
【.NET Developer】创建ASP.NET Core Blazor项目并打包为Linux镜像发布到Azure应用服务
本文介绍了如何使用VS2019和.NET框架创建一个Blazor应用,并将其部署到Azure应用服务。首先,Blazor是一个使用C#而非JavaScript构建交互式Web UI的框架,支持共享服务器和客户端应用逻辑,以及与Docker和Azure集成。任务包括创建Blazor项目,配置Dockerfile为Linux容器,本地测试,发布到Azure Container Registry (ACR),然后在Azure App Service for Container上部署。在部署过程中,需确保Docker设置正确,开启ACR的Admin访问权限,并监控镜像拉取和容器启动日志。
|
4月前
|
开发框架 前端开发 .NET
进入ASP .net mvc的世界
进入ASP .net mvc的世界
|
Web App开发 SQL 前端开发
一起谈.NET技术,鲜为人知的ASP.NET MVC 2.0框架高效之谜
  要想建立开发环境,你需要安装Visual Studio 2008/2010 Beta 2,以及SQL Express 2005(可免费从MSDN下载)和MVC 2.0框架。我把本文中的示例Web应用命名为“Employee Master Information”。
1007 0
|
存储 缓存 .NET
一起谈.NET技术,提高ASP.NET应用程序性能的十大方法
  一、返回多个数据集   检查你的访问数据库的代码,看是否存在着要返回多次的请求。每次往返降低了你的应用程序的每秒能够响应请求的次数。通过在单个数据库请求中返回多个结果集,可以减少与数据库通信的时间,使你的系统具有扩展性,也可以减少数据库服务器响应请求的工作量。
1218 0
|
Web App开发 .NET 数据安全/隐私保护
一起谈.NET技术,ASP.NET身份验证机制membership入门——项目
  前面说了很多关于membership的内容,感觉内容有点凌乱,内容都是一个个知识点,下面我们通过一个小的项目,来把所有的相关内容串一下。   首先描述一下需求:   我们要做一个最简单的网站。有三类用户:匿名用户,员工,管理员,网站结构如下:        admin目录下的页面只允许admin角色的用户访问,employee目录下的页面只允许emp角色的用户访问。
1100 0
|
缓存 算法 .NET
一起谈.NET技术,ASP.NET缓存全解析7:第三方分布式缓存解决方案 Memcached和Cacheman
  ASP.NET缓存全解析文章索引 ASP.NET缓存全解析1:缓存的概述 ASP.NET缓存全解析2:页面输出缓存 ASP.NET缓存全解析3:页面局部缓存 ASP.NET缓存全解析4:应用程序数据缓存 ASP.NET 缓存全解析5:文件缓存依赖 ASP.NET 缓存全解析6:数据库缓存依赖 ASP.NET 缓存全解析7:第三方分布式缓存解决方案 Memcached和Cacheman   Memcached — 分布式缓存系统    1.Memcached是什么?   Memcached是高性能的,分布式的内存对象缓存系统,用于在动态应用中减少数据库负载,提升访问速度。
1185 0