Results 1 to 5 of 5
-
December 10th, 2009, 05:11 PM #12,702Seņor Member
posts"toString" returns a String - Possible for more classes?
It seems as thought whenever you try to treat a class as a String (such as putting it inside of trace() or similar), if that class has a "toString" function, it will get the string from whatever that function returns, and will otherwise return something along the lines of "[object MyClass]".
Are there any more of these special functions?
Also, a bit of a far stretch, is there any way to do this with custom classes, for instance, your class may be a PolarPoint, but people can call "toLinearPoint()" and get an instance of a class which is a LinarPoint but with the same data.
Now, this is simple enough to do manually, but let's say you pass in the PolarPoint in a function where a LinearPoint is expected. Is it possible to make Flash automatically run the toLinearPoint() function if found? Similar to how Flash will run toString automatically if passed in as a String somewhere.
That second part is probably more of a hassle than it is worth though, but it would be REALLY handy if you are unable to extend two classes at once, but want your class to be able to be treated as both.Blog article of the month: Why My One Line 'if' Statements Are Unusual
Twitter: IQAndreas
GitHub: IQAndreas
-
December 10th, 2009, 05:21 PM #2
I'm guessing what you're talking about is akin to the C# intrinsic operators? http://msdn.microsoft.com/en-us/libr...8VS.71%29.aspx
I don't know of anything like that in ActionScript, but I hope there is!
-
December 10th, 2009, 05:28 PM #3
Kinda sounds like you are talking about the clone() method..
* [ Flash portfolio ] http://www.erikhallander.com/
* [ Flash blog ] http://www.erikhallander.com/blog/
* [ Work @ ] http://www.visualjazz.com.au
-
December 10th, 2009, 05:43 PM #4
I don't see what's special about trace. Yes, it calls toString, but it just does that from within. You can do that yourself and it's not special, you know?:
There's nothing in AS3 that's like the implicit operators that FizixMan mentioned (except it is done to a limited extent for primitive types, like you can add a String and a Number). Yep, it's too bad.Code:function f(...args):void { var i:int; for(var i:int = args.length; i >= 0; i++){ trace(args[i].toString()); } }
-
December 10th, 2009, 05:45 PM #5

Reply With Quote



Bookmarks