When building your first website in Flash you initially use the trace() function. But after a while you start to feel the need for more. There are a lot of ‘loggers’ available on the web. Personally I prefer Trazzle because it’s a very lightweight native mac application. But when working with colleagues who don’t use a mac, Trazzle is no option. It can be hard to choose a good logger everybody likes. That is why I created a project that enables you to use all the loggers you want with one simple script. I called it ‘Logger’ (don’t laugh). And you can use it with the following syntax:
Logger.debug("Logger traces a debug message");
That is not bad, right? Almost every logger has different debug levels, that is why I implemented the most important ones in the script (debug/error/fatal/info/critical/status/warning and notice). To log a message choose one of the following;
Logger.debug("Logger traces a debug message"); Logger.error("Logger traces an error message"); Logger.fatal("Logger traces a fatal message"); Logger.info("Logger traces an info message"); Logger.critical("Logger traces a critical message"); Logger.status("Logger traces a status message"); Logger.warning("Logger traces a warning message"); Logger.notice("And finally Logger traces a notice message");
Before you do this you first need to initialize the loggers you want. I created connectors for Trazzle, SOSMax, DeMonsterDebugger, Yala and Flash (trace). To enable all these loggers together (which is not recommended) call;
Logger.addLoggers([new MonsterDebuggerConnector(this),new FlashConnector(),new TrazzleConnector(),new YalogConnector(),new SosMaxConnector()]);
This is how the output looks on all the different connectors (note how every logger shows the line number and class of the log);
Trazzle (website)

De Monster Debugger (website)

SOSMax (website)

Yala (online version)

Flash:

I created a zip package with everything you need (Demo FLA and source). If you have any suggestions please let me know!
Today I have built a wrapper around some loggers for Flash (Trazzle, Yalog, Monster Debugger and SOS Max).
I am currently cleaning the code, but I will post the code as soon as possible.
This is a screenshot of my current setup….
Today I started to work on a .srt driven subtitle system for Flash, I just finished that converts the srt file to a native flash object.
Below is a short sample of a srt file.
1 00:00:20,000 --> 00:00:24,400 In connection with a dramatic increase in crime in certain neighbourhoods, 2 00:00:24,600 --> 00:00:27,800 the government is implementing a new policy...
I created the following classes to read these files. (any suggestions are welcome!)
Special thanks to Thijs Broerse of Media Monks, for the stringToSeconds function
SubtitleParser.as
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | package nl.inlet42.data.subtitles { /** * @author Jankees.van.Woezik */ public class SubtitleParser { public static function parseSRT(data : String) : Array { var result : Array = new Array(); var lines : Array; var translation : SubTitleData; var blocks : Array = data.split(/^[0-9]+$/gm); for each (var block : String in blocks) { translation = new SubTitleData(); lines = block.split('\n'); for each (var line : String in lines) { //all lines in a translation block if(trim(line) != "") { if(line.match("-->")) { //timecodes line var timecodes : Array = line.split(/[ ]+-->[ ]+/gm); if(timecodes.length != 2) { trace("Translation error, something wrong with the start or end time"); } else { translation.start = stringToSeconds(timecodes[0]); translation.end = stringToSeconds(timecodes[1]); translation.duration = translation.end - translation.start; if(translation.duration < 0) { trace("Translation error, something wrong with the start or end time"); } } } else { //translation line if(translation.text.length != 0) line = "\n" + trim(line); translation.text += line; } } } result.push(translation); } return result; } public static function trim(p_string : String) : String { if (p_string == null) { return ''; } return p_string.replace(/^\s+|\s+$/g, ''); } /** * Convert a string to seconds, with these formats supported: * 00:03:00.1 / 03:00.1 / 180.1s / 3.2m / 3.2h / 00:01:53,800 * * Special thanks to Thijs Broerse of Media Monks! * **/ public static function stringToSeconds(string : String) : Number { var arr : Array = string.split(':'); var sec : Number = 0; if (string.substr(-1) == 's') { sec = Number(string.substr(0, string.length - 1)); }else if (string.substr(-1) == 'm') { sec = Number(string.substr(0, string.length - 1)) * 60; }else if(string.substr(-1) == 'h') { sec = Number(string.substr(0, string.length - 1)) * 3600; }else if(arr.length > 1) { if(arr[2] && String(arr[2]).indexOf(',') != -1) arr[2] = String(arr[2]).replace(/\,/, "."); sec = Number(arr[arr.length - 1]); sec += Number(arr[arr.length - 2]) * 60; if(arr.length == 3) { sec += Number(arr[arr.length - 3]) * 3600; } } else { sec = Number(string); } return sec; } } } |
SubTitleData.as
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | package nl.inlet42.data.subtitles { public class SubTitleData { public var text : String; public var start : Number; public var duration : Number; public var end : Number; public function SubTitleData(inText : String = "",inStart : Number = 0,inDuration : Number = 0,inEnd : Number = 0) { text = inText; start = inStart; duration = inDuration; end = inEnd; } public function toString() : void { trace("nl.inlet42.data.subtitles.SubTitleData"); } } } |
Update: Thanks to Tiago for the update.
For my current project I needed something to slice an image easily, first I tried to slice the image with a mask, but I soon found out that this much heavier than my current solution.
Below is the end result I needed to have (the triangle is a big mask).
// image = a MovieClip with an image // upper part var upperBitmapData:BitmapData = new BitmapData(image.width,image.height / 2); upperBitmapData.draw(image); mUpperBitmap = new Bitmap(upperBitmapData); addChild(mUpperBitmap); //lowerpart var lowerMatrix:Matrix = new Matrix(); lowerMatrix.ty = -(image.height / 2); var lowerBitmapData:BitmapData = new BitmapData(image.width,image.height / 2); lowerBitmapData.draw(image,lowerMatrix); mLowerBitmap = new Bitmap(lowerBitmapData); mLowerBitmap.y = ContentClip.MASK_HEIGHT / 2; addChild(mLowerBitmap); image = null;