搞定AS3的remoting
今天终于把AS3的一个remoting的小项目搞定了,呵呵,搞了好几天,终于把这个小东西完成了.呵呵~~~今天把一个AS3的remoting的最简单的例子贴出来给初学者看看吧~~~呵呵,其实蛮容易的~~~
HelloFlashAS3.fla
import flash.net.*;
var HostName:String = "http://localhost/TestSite/";
var gatewayUrl:String = HostName+"gateway.aspx";
////////////////////////////
var nc:NetConnection = new NetConnection();
nc.objectEncoding = 0;//使用as1和as2兼容的amf编码
nc.connect(gatewayUrl);
nc.call("TestSite.HelloFlash",new Responder(onResult,onFault));//调用并传递参数
msg_txt.text="数据加载中..."
function onResult(re:Object) {
msg_txt.text=re.toString();
}
function onFault(re:Object) {
msg_txt.text="加载错误"
for (var i in re) {
trace(i+"=>"+re[i]);
}
}
HelloFlash.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="HelloFlash.aspx.cs" Inherits="HelloFlash" %>
<%@ Register TagPrefix="Macromedia" Namespace="FlashGateway" Assembly="flashgateway" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<Macromedia:Flash ID="Flash" runat="server" />
</div>
</form>
</body>
</html>
cs文件:
protected void Page_Load(object sender, EventArgs e)
{
Flash.Result = "Hello World!!!";
}