views:

359

answers:

2

Hi,

I'm doing a AS3 project in Eclipse and trace alot of values. I though it would be nice to have a toString() function in every class, at the bottom of each class as the last function, but i dont want to do this by hand for 500+ files. Is there a quick and good way of doing this automated?

How would you go about this?

Thanks in advance,

Sidney

A: 

You could certainly write a script to accomplish a toString() stub using regex, but I presume you want a meaningful toString().

Since toString() is for humans, only a human can look at a class and know what information to include.

FarmBoy
Well the thing is in AS3 that if i subclass from Sprite or any other visual class i get a trace with [object Sprite] instead of the actual class name.So what i want to include in my toString() function is;override public function toString() : String { return getQualifiedClassName(this); }So it returns to me the full class name like com.domain.project.ClassName instead of the [object Sprite]
Sidney
A: 

If you have access to the classes the objects were based on, add it there and it will be available to all other classes via inheritance.

If not, then instead of trying to add it to 500 classes you might want to spend the time refactoring and subclass the base object into your own, then have all the classes inherit from that.

The first incarnation will be a simple subclass with your name and the new toString() attached.... Then the next time you need to add functionality you want everywhere you can add it here, recompile and voila, it is available everywhere.

David Mann