Customizing toString()

By sascha, September 8, 2008 – 2:15 am -

When writing classes for a framework I usually put a custom toString method into important classes so that debugging becomes easier. Normally they would go like something along the lines of:

override public function toString():String {
	return "[ClassName]";
}

… Sometimes adding properties to the returned String that give back information about the class, e.g.

override public function toString():String {
	return "[ImageClass, size=" + _size + "]";
}

But writing them rigid like that is a disadvantage when you decide later to refactor class names. Admittedly it’s also not a very elegant way so I got the idea to take the class name that is returned by getQualifiedClassName(). The only problem is that getQualifiedClassName not only provides the type name but also the whole package String of the class. Regular Expressions to the rescue! After twiddling around with them for a while (I’m by no means a RegExp expert) I got my toString method into the shape that I desired:

override public function toString():String {
	return "[" + getQualifiedClassName(this).match("[^:]*$")[0] + ", size=" + _size + "]";
}

This way it matches the String returned by getQualifiedClassName with the Regular Expression [^:]*$ which checks from the right end for an arbitrary text up to the first occurring colon, but without including the colon. Taking the first element of the Array returned by match() and you got what you need!

A nice way of using this is when writing abstract classes that contain the toString method and any subclass can use that toString method without the need to override it … that is of course unless you want ot add other output information.

Aw Snap! This site is not meant for you!

By sascha, September 6, 2008 – 2:22 pm -

Chrome, the new snazzy browser from Google is currently in everyone’s mouth and most people who had a look at it seem to be impressed so I decided to give it a go, after all it can’t be so bad, right?

Chrome installs right onto your system from the website and then takes over (or if you are cynical: steals) all the bookmarks, history, passwords etc. from Firefox (to make your life easier). It then opens with a slick and slender window that lacks all the tackiness of a plugin-convoluted Firefox. When opening a new tab it shows a neat history list with thumbnails of your most recent visited websites. Chrome starts up as fast as a finger snap! Maybe even faster! Can it get any better?

Read the rest of this entry »

Featured

Alcon

Alcon is a lightweight debugging tool for ActionScript developers that provides several straightforward and quickly accessible methods to debug any ActionScript 2 or ActionScript 3 application, be it from the Web Browser, the standalone Flash Player or an AIR Runtime. It offers an easy way to output debug information from anywhere, not just while in the Flash IDE or in the Flex Debugger. It comes packed with an Application Monitor that can monitor the framerate and memory consumption, an Object Inspector for viewing the properties of any Object, Array or Class and up to two File Loggers. Alcon runs on any platform that supports Adobe AIR and can be used with the Flex compiler, the Flash IDE or MTASC.

Continue Reading »

Coin-Op Shooter hysteria in your living room

July 6, 2003 – 2:06 pm

Review: V-Scroll-Shoot'em'ups with MAME Nothing rocks more for a spontaneous minute fun than playing a session of arcade shoot'em'ups! They always kicked up the limit of graphic power in the eighties ...

Review: Animatrix - Beyond

June 27, 2003 – 11:38 am

I'm going to review here only on the episode 'Beyond' from the Animatrix movies as it's my very favorite (together with 'Detective Story') on there. Director Koji Morimoto had the ...

Harry Palmer, the only true spy!

June 26, 2003 – 9:51 am

Incidentally switched onto communal TV program tonight to catch up the most of the rest of Funeral in Berlin, an excellent spy movie from 1966 with Michael Caine starring ...

How to glitch like a pro!

June 24, 2003 – 9:48 am

what professional graphic interface designers usually want to avoid is glitch art for others and there's a whole gallery of it plus a howto-glitch tutorial. featuring plenty of screenshots of ...

Aliens and a lot of pixel blood

June 23, 2003 – 9:28 am

Review: Project Firestart (C64) [caption id="attachment_288" align="alignright" width="220" caption="We enter!"][/caption] Time for another classic game review: today it's one of my very favorites back on the C64, the space horror action adventure ...

C64 pocketized

June 22, 2003 – 9:21 am

[caption id="attachment_294" align="alignright" width="200" caption="C64-Paradroid played on GBA (a study)"][/caption] it looks tempting! the author of splam.emuhq.com is working on a *C64 emulator* for the Gameboy Advance™! He's already busy since ...

Skinjob Delicatessen

June 22, 2003 – 9:16 am

There are people who are completely captivated by Blade Runner and I'm somewhere between them and the halfway of being absorbed. If you don't count to them, there's a good ...

DreamTopCast

June 22, 2003 – 9:05 am

engaged console modders in HK tinkered together the first Dreamcast(tm) with LCD display! Looks quite funny the bumpy DC with a LCD on top! It doesn't make it more portable ...

Dr. Colossus’ Adventures in Slime World

June 21, 2003 – 9:08 am

Review: Todd's Adventures In Slime World (Atari Lynx) Do you remember the Lynx™? That was Atari's approach in the late 80ties/early 90ties to get onto the Handheld market! ... now ...

the daily photo project

June 20, 2003 – 9:04 am

And then there was the boy who shot a photo of himself everyday since 1998 and uploaded it to his website. interesting to look at the difference between the early ...

Welcome to H1DD3N.R350URC3!

These are the adventures of a random guy trying to be an independant game developer, utilizing ActionScript for programming and talking abouting gaming and nonsense in general.

Need any news feed?

 Main Feed (contains all categories), Dev Feed, Design Feed, Audio Feed, Gaming Feed, Miscellaneous Feed
Find entries: