Skip to content

Instantly share code, notes, and snippets.

@ltudury
Last active December 21, 2015 08:18
Show Gist options
  • Save ltudury/6277207 to your computer and use it in GitHub Desktop.
Save ltudury/6277207 to your computer and use it in GitHub Desktop.
Sample snippet of ActionScript code to send events to Loggly
package {
import flash.display.Sprite;
import flash.events.ErrorEvent;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.SecurityErrorEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.text.TextField;
[SWF(width="800", height="600", frameRate="30", backgroundColor="#888888")]
public class Loggly extends Sprite {
public var textField:TextField;
public function Loggly() {
textField = new TextField();
textField.width = 800;
textField.height = 600;
addChild(textField);
log("sending event...");
sendEvent();
}
public function log(message:String):void {
trace(message);
textField.appendText(message + "\n");
}
public function sendEvent():void {
var url:String = "http://logs-01.loggly.com/inputs/";
// Use your own Customer Token here
var token:String = "026308d8-2b63-4225-8fe9-e01294b6e472";
var request:URLRequest = new URLRequest(url + token);
request.method = URLRequestMethod.POST;
request.data = "{\"message\": \"Hello from ActionScript!\"}";
var requestor:URLLoader = new URLLoader();
requestor.addEventListener( Event.COMPLETE, httpComplete );
requestor.addEventListener( IOErrorEvent.IO_ERROR, httpFail );
requestor.addEventListener( SecurityErrorEvent.SECURITY_ERROR, httpFail );
requestor.load( request );
}
private function httpComplete( event:Event ):void {
log("Completed: " + event);
}
private function httpFail( error:ErrorEvent ):void {
log("FAILED: " + error);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment