我为JSON Encode和Decode编写了一个AS 3.0代码,但我需要在AS 2.0中编写以下代码。我知道AS 3.0但不知道AS 2。
以下是代码:
stop();
var getFBId:String = ExternalInterface.call("getFBIdFromJS");
var getFBName:String = ExternalInterface.call("getFBNameFromJS");
import com.adobe.serialization.json.JSON;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLVariables;
import fl.transitions.*;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
import flash.display.MovieClip;
import flash.events.MouseEvent;
playerInformation.visible = true;
var loginObj:Object = new Object();
var fbId:String = new String();
var Id:String = new String();
var varUid:String = new String();
var ImageUrl:String = new String();
var CreditBalance:String = new String();
//var PointBalance:String = new String();
var CoinBalance:String = new String();
var IsDailyBonus:String = new String();
var DailyBonusAmount:int = new int();
var fbvarsLoader:URLLoader = new URLLoader();
var fbvarsReq:URLRequest = new URLRequest("fbvars.php");
var fbvarsVariables:URLVariables = new URLVariables();
fbvarsLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
fbvarsReq.method = URLRequestMethod.POST;
fbvarsReq.data = fbvarsVariables;
fbvarsLoader.load(fbvarsReq);
fbvarsLoader.addEventListener(Event.COMPLETE, receiveLoad);
function receiveLoad(evt:Event):void
{
fbId = getFBId;
varUid = getFBName;
ImageUrl = "https://graph.facebook.com/" + getFBId + "/picture";
trace (getFBId);
trace (getFBName);
trace (ImageUrl);
loginObj.FacebookId = fbId;
loginObj.UserName = varUid;
loginObj.PlatformId = 1;
loginReq.data = JSON.encode(loginObj);
loginLoader.load(loginReq);
trace("login ENCODE: " + JSON.encode(loginObj));
FBlogindata.text = JSON.encode(loginObj);
}
//--------------- FB Vars (E)
var serverURL:String = "http://serverURL";
var playerPicLoader:Loader = new Loader();
//--------------------------------
var loginReq: URLRequest = new URLRequest();
loginReq.method = URLRequestMethod.POST;
loginReq.url =
"http://serverURL";
var loginLoader:URLLoader = new URLLoader();
loginLoader.addEventListener(Event.COMPLETE, onComplete_login);
function onComplete_login(e_login:Event)
{
var loginReturn:Object=JSON.decode(e_login.target.data,true);
trace("login DECODE: " + e_login.target.data);
logindata.text = e_login.target.data;
if (loginReturn.Player.Status == "Valid")
{
Id = String(loginReturn.Player.Id);
CreditBalance = String(loginReturn.Player.CreditBalance);
var playerPic:URLRequest = new URLRequest(ImageUrl);
playerPicLoader.load(playerPic);
playerInformation.mcPlayerThumbHolder.addChild(playerPicLoader);
playerInformation.txtPlayerName.text = varUid;
playerInformation.txtPlayerCredit.text = CreditBalance;
playerInformation.visible = true;
UIDShow.text = Id;
FBIDShow.text = fbId;
if (this.parent.parent != null){
trace (CreditBalance);
MovieClip(this.parent.parent).credit = CreditBalance;
}
}
}
任何人都可以在AS 2.0中编写上述代码吗?
答案 0 :(得分:0)
这是implementation of AS2 JSON parser。有两种静态方法stringify()
- 用于编码为JSON,parse()
用于解码。所以你不必编写自己的实现。对于其他东西,你应该坐下来学习一些关于AS2的东西,或找一个还记得AS2的人:)