0 Replies Latest reply on Dec 10, 2009 3:24 PM by msakrejda

    Coercion functions for custom data types?

    msakrejda Level 4

      Sorry for the dupe--I asked this in the ActionScript forum a couple of days ago, but got nothing. I'm more familiar with the Flex forum and have gotten very helpful not-strictly-Flex answers here previously; I hope someone can help, and that this can be considered a cross-forum bump in rather than a cross post. Anyway, here's my question:

       

      Flash defines some coercion functions in ActionScript 3 that behave differently than plain casts. E.g.,

       

      String(0) == '0'

       

      but

       

      (0 as String) == null

       

      Is there a way to define similar coercion functions for custom data types? I'm working with the Flex framework, and looking in Global.as, I can see both a String class ( public final class String, with constructor public native function String(val:String); ) and a String function ( public native function String(expression:Object):String ). Both of these are in the default package, although apparently separate declartions of the default package within Global.as.

       

      I attempted to implement something similar with my own data types, but mxmlc is not too crazy about my ideas: it complains about a duplicate function definition. Is there any way to achieve this, or is this only for built-in types?