Create a gist now

Instantly share code, notes, and snippets.

@yohanes /url.as Secret
Created Nov 7, 2016

What would you like to do?
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