Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Flex app

  • Loading branch information...
commit 1467c9aed97ab24206962e1fe31019b23466f7a4 1 parent 1868f44
@eoftedal authored
View
9 flex/README.txt
@@ -0,0 +1,9 @@
+Configuration
+-------------
+Change the following line to point to the server and port where the backend is running:
+ socket.connect("localhost", 8081);
+
+
+How to compile
+--------------
+mxmlc --strict=true --file-specs malariaproxy.mxml
View
23 flex/malariaflexproxy.html
@@ -0,0 +1,23 @@
+<html>
+<head>
+<script>
+function log(msg) {
+ var elm = document.getElementById("log");
+ elm.innerHTML += msg + "<br />";
+}
+
+</script>
+</head>
+<body>
+<h3>MalaRIA Proxy</h3>
+<div id="log">
+</div>
+
+
+<object width="0" height="0">
+<param name="movie" value="malariaproxy.swf">
+<embed src="malariaproxy.swf" width="0" height="0">
+</embed>
+</object>
+</body>
+</html>
View
67 flex/malariaproxy.mxml
@@ -0,0 +1,67 @@
+<?xml version="1.0" ?>
+<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
+xmlns="*" creationComplete="useHttpService()">
+ <mx:Script>
+ <![CDATA[
+ import mx.controls.Alert;
+ import mx.rpc.http.HTTPService;
+ import mx.rpc.events.ResultEvent;
+ import mx.rpc.events.FaultEvent;
+ import flash.external.*;
+ private var socket:Socket;
+
+ public function useHttpService():void {
+ socket = new Socket();
+ ExternalInterface.call("log", "Connecting back to malaria server...");
+ socket.addEventListener(Event.CONNECT, this.connectHandler);
+ socket.addEventListener(ProgressEvent.SOCKET_DATA, this.onData);
+ socket.connect("localhost", 8081);
+ }
+ private function onData(event:ProgressEvent):void
+ {
+ ExternalInterface.call("log", "Got data from proxy");
+ var data:String = socket.readUTFBytes(socket.bytesAvailable);
+ var url:String = getValue(/.* (.*) .*/, data);
+ handle(url);
+ }
+
+ public function connectHandler(event:Event):void
+ {
+ ExternalInterface.call("log", "Connected and ready");
+ socket.writeUTFBytes("Hello");
+ socket.flush();
+ }
+
+ public function handle(url:String):void {
+ ExternalInterface.call("log", "Trying: [" + url + "]");
+ var service:HTTPService = new HTTPService();
+ service.url = url;
+ service.resultFormat = "text";
+ service.addEventListener("result", this.httpResult);
+ service.addEventListener("fault", this.httpFault);
+ service.send();
+ }
+
+ public function httpResult(event:ResultEvent):void {
+ var result:String = event.result.toString();
+ socket.writeUTFBytes(result.length + ":" + result);
+ socket.flush();
+ ExternalInterface.call("log", "Sending back data - length " + result.length);
+ }
+
+ public function httpFault(event:FaultEvent):void {
+ var faultstring:String = event.fault.faultString;
+ ExternalInterface.call("log", "FAULT:" + faultstring);
+ socket.writeUTFBytes("HTTP/1.1 502 Not accessible");
+ socket.flush();
+ ExternalInterface.call("log", "Sending back 502");
+ }
+
+ public function getValue(pattern:RegExp, result:String):String {
+ var regresult:Object = pattern.exec(result);
+ return regresult[1];
+ }
+
+ ]]>
+ </mx:Script>
+</mx:Application>
View
BIN  flex/malariaproxy.swf
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.