Last active
December 21, 2015 08:18
-
-
Save ltudury/6277207 to your computer and use it in GitHub Desktop.
Sample snippet of ActionScript code to send events to Loggly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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