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 ยป

Loading Zip files into Flash … yummy!

November 20, 2006 – 3:08 pm

This might be old news for you but I've just coincidentally stumbled over an ActionScript 3 class named FZip that was written by Claus Wahlers and Max Herkender which provides ...

Flash your own Converse Sneaker together

November 19, 2006 – 1:34 pm

Just found this yesterday via Adobe Consulting Blog ... Converse - Chuck Taylor, Jack Purcell, Basketball Shoes, Design Your Own Converse Shoes. Click on the first shoe under Collection. You ...

Understanding Interfaces and Polymorphism

November 18, 2006 – 8:12 pm

I've been using Interfaces a couples of time now when needed but I never fully understood those down-sized Class construct wannabes. I knew they are useful when it is required ...

Tools of the Nuisance Part 1: XMLSpy

November 18, 2006 – 12:03 am

If you're working with XML on Windows and you like your tool full-featured there's a good chance that you have worked with Altova XMLSpy, a first of all very good ...

Vista and the missing compatible Software

November 17, 2006 – 3:06 pm

[ad#ad_content]I've made a partition with Windows Vista RC a while back to check out how well my used Software will run. First off I like Vista, I really do! It's ...

Fotologue - The Japanese answer to Flickr

November 9, 2006 – 2:33 pm

Fotologue which was Japanese only for a while has been translated into English and opened up it's gates for anyone else around the globe! Not only does it look much ...

Waiting for AS 3.0 Books

October 16, 2006 – 5:30 pm

A couple of days ago the ActionScript 3.0 Cookbook has been published. Obviously it's a Must-Have but so far I resisted to buy it, waiting for some User Reviews on ...

PowerFlasher announces FDT v1.5 Update

September 27, 2006 – 12:50 pm

It was about time! According to PowerFlasher a new (and free) update of FDT is due in October. But it will not support AS3/Flex, this will come in quartal 1/2007. I ...

ePaper - When is it feasable?

September 26, 2006 – 7:51 pm

I'm really missing one great invention that has yet to come for global consumption ... books made of electronic paper! I'm not talking about these LCD display-like books or these ...

Fixing other people’s code

September 22, 2006 – 1:44 pm

I just had to refuse the second job offer this year where I would have to fix somebody else's written ActionScript 1 spagetti code! I don't know what is the ...

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: