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.
Featured
FEAT (Freelancer’s Estimation Assistance Tool)
FEAT (abbreviation for Freelancer’s Estimation Assistance Tool) is a tool to help freelancers calculate hourly rates and project pricing estimates. It is inspired by a very similar calculation PDF sheet which was created by Lauren of creativecurio.com and by some other useful freelancer pricing resources on the net.
The tool uses the same calculations like the ones from the links mentioned above plus it stores your values so you don’t have to enter them again every time. Version 1.0 features hourly rate calculation, a project pricing wizard and an option to change the visual theme of the tool. It also resides nicely on your desktop or wherever you put it and is there whenever you need to make an estimation.
Continue Reading »Changing the Syntax Color in Flex Builder 2.0
May 24, 2006 – 7:47 pmMike Morearty of Adobe wrote in his blog how to change the syntax colors in Flex Builder 2.0. This is useful stuff since I loathe the default blue and green ...
Fun with SWG NGE
May 14, 2006 – 9:34 pm... I'm not talking about fun with playing the NGE mind you ... when the NGE came live there was a lot of derision and mockery on the official forums. ...
MXNA doesn’t like me!
May 14, 2006 – 12:14 amI'm chased by bad luck since a while when it comes to getting this blog onto the Macromedia XML News Aggregator! First when I used Nucleus CMS it stopped fetching ...
Does Flex needs it’s own JRE?
May 13, 2006 – 1:41 amShort answer: no! Full answer here. However when I had Flex2 beta2 installed, I deleted the JRE that installed with Flex because I already had the JRE 5.0 installed and ...
FC64 - C64 Emulator in Flash
May 12, 2006 – 2:58 pmEverybody has probably by now blogged about this but Claus Wahlers and Darron Schall are writing a Commodore C64 emulator in ActionScript 3.0! It is still to early to tell ...
Flex Application: Star Wars Name Generator
May 11, 2006 – 2:35 pmI finally spend some time to make myself more familiar with the Flex 2 Beta and this is what came out as a result: Star Wars Name Generator! It's a ...
The Joys of Public Beta
May 10, 2006 – 3:38 pmFlex 2 public beta3 was just released and already all formerly written Flex2 beta2 apps started to fail working in the newest Flash Player! Seems like Adobe is making critical ...
Raised from the dead
May 10, 2006 – 12:54 amFinally I got myself up to completely overhaul this blog and after a long time of resisting I finally decided to switch to Word Press! Nucleus was a great system ...
Star Wars Wiki
April 1, 2006 – 5:09 amWookiepedia, a Wiki solely dedicated to the Star Wars universe! How nice to see that some people have already been very busy filling the database with tons and tons of ...
Game Over for SOE about Star Wars Galaxies?
March 22, 2006 – 3:47 pmIf we can believe these rumors originally from mmorpg.com it looks like Star Wars Galaxies is very soon history for Sony Online Entertainment. According to the news Lucas Arts withdraw ...
| Filed under »