AS2 → AS3: LoadVars AS3 Equivalent
来源:互联网 发布:男生淘宝网名昵称大全 编辑:程序博客网 时间:2024/05/22 02:11
ActionScript 3 has done away with the LoadVars class and when I was updating my ContactForm for AS3 I was trying to figure out how to mimic the sendAndLoad() method that LoadVars provided. I stumbled upon an article by Peter Elst which explained how to do this so I'm going to outline the differences here.
Let's take a look at the old AS2 code:
Actionscript:
- var msg:LoadVars = new LoadVars();
- var msgSent:LoadVars = new LoadVars();
- msg.var1 = "one";
- msg.var2 = "two";
- msgSent.onLoad = function($success:Boolean):Void
- {
- if ($success)
- {
- trace("Message sent.");
- }
- else
- {
- trace("Message failed.");
- }
- };
- msg.sendAndLoad("http://www.reintroducing.com/script.php", msgSent);
And here is the AS3 equivalent:
Actionscript:
- var scriptRequest:URLRequest = new URLRequest("http://www.reintroducing.com/script.php");
- var scriptLoader:URLLoader = new URLLoader();
- var scriptVars:URLVariables = new URLVariables();
- scriptLoader.addEventListener(Event.COMPLETE, handleLoadSuccessful);
- scriptLoader.addEventListener(IOErrorEvent.IO_ERROR, handleLoadError);
- scriptVars.var1 = "one";
- scriptVars.var2 = "two";
- scriptRequest.method = URLRequestMethod.POST;
- scriptRequest.data = scriptVars;
- scriptLoader.load(scriptRequest);
- function handleLoadSuccessful($evt:Event):void
- {
- trace("Message sent.");
- }
- function handleLoadError($evt:IOErrorEvent):void
- {
- trace("Message failed.");
- }
As you can see, there is a new URLVariables class that stores the information you want to pass to your script. You then pass that URLVariables instance to the URLRequest's data property. Essentially, what this does, is create a query string with all the variables appended to it. The above actually looks like this when it is sent to the server:
http://www.reintroducing.com/script.php?var1=one&var2=two
That is what the PHP script receives and then handles it on the script's end to do whatever it is that you are wanting to do. I also explicitly set the URLRequest's method to be POST by setting the URLRequestMethod.POST constant (for GET, you'd just set URLRequestMethod.GET).
http://evolve.reintroducing.com/2008/01/27/as2-to-as3/as2-%E2%86%92-as3-loadvars-as3-equivalent/
- AS2 → AS3: LoadVars AS3 Equivalent
- As3 模拟As2.0 LoadVars传参
- 从AS2到AS3
- as2 as3 不同
- 关于AS2和AS3
- as2与as3应用
- 【AS3与AS2通信】AVM2 (AS3) to AVM1 (AS2/AS1)
- as3与as2的区别
- 基础as2 转AS3笔记
- as3程序员不知道的as2和as3的不同点
- as2和as3的性能比较
- AS2与AS3的主要差别
- AS2.0和AS3.0的区别
- Flash as3 as2 鼠标右键事件触发
- flash as2和as3添加外部声音
- AS2中的_root,在AS3的用法
- 浅谈as2.0与as3.0
- AS3
- char*转换CString 、CString转换为char *、连接char* 串
- 利用REST配置GeoServer
- 汉字字符串长度判断
- 找出最大的前K个数
- 劳动合同法中对竞业限制的规定
- AS2 → AS3: LoadVars AS3 Equivalent
- 应用于客户端的性能测试指标
- C# 中的委托和事件(http://www.tracefact.net/CSharp-Programming/Delegates-and-Events-in-CSharp.aspx)
- 继续努力
- 利用GPU进行高性能数据并行计算《程序员》2008年第4期
- cisco 路由器:ADSL拨号的设置
- 使用jQuery的load(url)加载网页的替代方案--不用考虑编码的问题
- 高斯分布函数解析
- CSS 命名规范