From b816a45b4d8e9e6bdb7a4fa1555caeea88e28385 Mon Sep 17 00:00:00 2001 From: Jeremy Penner Date: Mon, 16 May 2011 23:56:34 -0700 Subject: [PATCH] add the ability to save QTEs by POSTing to a given URL --- src/Gamedisc.as | 21 ++++++++++++++++++++- src/Main.as | 2 -- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/Gamedisc.as b/src/Gamedisc.as index 2a76bec..ab86dac 100644 --- a/src/Gamedisc.as +++ b/src/Gamedisc.as @@ -1,6 +1,11 @@ package { + import com.adobe.serialization.json.JSON; import flash.events.EventDispatcher; + import flash.net.sendToURL; + import flash.net.URLRequest; + import flash.net.URLRequestMethod; + import flash.net.URLVariables; /** * ... * @author jjp @@ -11,6 +16,7 @@ package public static const VIDEOTUBE_YOUTUBE:String = "yt"; public var urlVideo:String; + public var urlPostQte:String; public var typeVideotube:String; public var rgqte:Array; public function Gamedisc(urlVideo:String = null, typeVideotube:String = null) @@ -22,6 +28,15 @@ package public function AddQte(qte:Qte):void { rgqte.splice(Math.abs(Util.binarySearch(rgqte, qte, Qte.compare)), 0, qte); + if (urlPostQte != null) + { + var req:URLRequest = new URLRequest(urlPostQte); + req.method = URLRequestMethod.POST; + var data:URLVariables = new URLVariables(); + data.qte = JSON.encode(qte.ToJson()); + req.data = data; + sendToURL(req); + } } public function CreateVideotube():Videotube { @@ -36,7 +51,10 @@ package var jsonRgqte:Array = []; for each (var qte:Qte in rgqte) jsonRgqte.push(qte.ToJson()); - return { urlVideo: urlVideo, typeVideotube: typeVideotube, rgqte: jsonRgqte }; + var json:Object = { urlVideo: urlVideo, typeVideotube: typeVideotube, rgqte: jsonRgqte }; + if (urlPostQte != null) + json.urlPostQte = urlPostQte; + return json; } public function FromJson(json:Object):void { @@ -49,6 +67,7 @@ package } urlVideo = json.urlVideo; typeVideotube = json.typeVideotube; + urlPostQte = json.urlPostQte; } } diff --git a/src/Main.as b/src/Main.as index 28fa03f..81f154e 100644 --- a/src/Main.as +++ b/src/Main.as @@ -19,14 +19,12 @@ package private var gamedisc:Gamedisc; private var gameeditor:GameEditor; private var gameplayer:GamePlayer; - private var fPlayOnly:Boolean; public function Main():void { gamedisc = new Gamedisc(); gamedisc.FromJson(JSON.decode(loaderInfo.parameters.jsonDisc)); videotube = gamedisc.CreateVideotube(); - fPlayOnly = JSON.decode(loaderInfo.parameters.fPlay); if (stage) init(); else addEventListener(Event.ADDED_TO_STAGE, init); }