AS3 - Returning a property of a class rather than the class itself?

If you wan't your object to trace out your own fabricated string then you must implement a toString() function on your AvLevelData class.

If you wan't your object to trace out your own fabricated string then you must implement a toString() function on your AvLevelData class. In your example above, the MovieClip trace outputs: Object MovieClip; this comes from the default toString() implementation for Object (found on Object. Prototype) .

Note, you cannot override toString() as it only exists on the prototype of Object (remnants of the AS2/Javascript world), all you need to do is provide your own implementation with the same name. For instance: public function toString():String { return "MyCustomObjectString"; }.

Perfect - thanks for the concise explanation around why this doesn't need to be implemented using override - that would have caused me some headaches. – Marty Wallace Nov 30 '11 at 6:31 No problem! As an interesting aside: the prototype is still functional in AS3, for instance you could create a custom default toString() implementation for all Object instances.

For example, try this: Object. Prototype = function():String { return "DefaultString" }. Now when you trace your plain MovieClip (or any other Object) instance, it will return DefaultString instead.

Note: it's generally highly unrecommended to provide alternative implementations to standard functions on the prototype; but it's a good educational example. – Peter Nov 30 '11 at 6:38.

Some of the most basic types - String, int, Number, uint, Boolean, to name a few - are not classes / objects per se, they are primitives. In some languages there is a wrapper class available for some of these so they can be treated like objects, though Flash doesn't do this so much from my experience. Probably the best way to answer your question is to make a toString() method for your AvLevelData class: public function toString():String { return data; } Any time you treat a class as a string (such as by putting it in trace()), flash (and many other languages) try to call toString() on the object.

Typically this results in a string that's not helpful. But if you define your own toString() method, you can control what string gets output. Another option is to simply do: trace(AvLevelData.

Data); Since that variable is a string, it should trace just fine.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions