Skip to content

Instantly share code, notes, and snippets.

@yohanes

yohanes/url.as Secret

Created November 7, 2016 01:57
Show Gist options
  • Save yohanes/d3535aa1fe0230ef4ee9a51ada84dc24 to your computer and use it in GitHub Desktop.
Save yohanes/d3535aa1fe0230ef4ee9a51ada84dc24 to your computer and use it in GitHub Desktop.
Actionscript logging to URL
package
{
import flash.events.*;
import flash.net.*;
import flash.display.*;
import flash.utils.ByteArray;
import flash.utils.describeType;
public class url
{
private static var URL:String = "http://localhost/log.php";
public static function doSend(str:String):void
{
var request:URLRequest = new URLRequest(str);
var loader:URLLoader= new URLLoader();
loader.load(request);
}
public static function sendPostData(q:String, sdata:String):void
{
var loader : URLLoader = new URLLoader;
var urlreq:URLRequest = new URLRequest(URL+q);
var urlvars: URLVariables = new URLVariables;
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
urlreq.method = URLRequestMethod.POST;
urlvars.data = sdata;
urlreq.data = urlvars;
loader.load(urlreq);
}
//just for basic testing
public static function testSendVoid():void
{
var url:String = URL + "?BASIC_TEST";
doSend(url);
}
//for tracing
public static function testSendNumber(num:int):void
{
var url:String = URL + "?NUMBER=" + String(num);
doSend(url);
}
public static function testSendString(s:String):void
{
var url:String = URL + "?STRING=" + s;
doSend(url);
}
public static function testSendObjectType(o:*):void
{
sendPostData("?ObjectDesc", String(describeType(o)));
}
public static function fromArray(array:ByteArray, colons:Boolean=false):String {
if (array==null) {
return "null";
}
var s:String = "";
for (var i:uint=0;i<array.length;i++) {
s+=("0"+array[i].toString(16)).substr(-2,2);
if (colons) {
if (i<array.length-1) s+=":";
}
}
return s;
}
public static function testSendBA(b:ByteArray):void
{
sendPostData("?ByteArray", fromArray(b));
}
public static function sendData(num: int, str: String):void
{
var url:String = URL + String(num) + "/" + str;
doSend(url);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment