Tip to adobe docs... :)

That last paragraph would be perfect in page about casting types. :)

Peace, Mike

On 1/11/07, Peter Farland <[EMAIL PROTECTED]> wrote:

   Most of the intrinsic types have global functions defined that create
new instances, as does Array().

http://livedocs.macromedia.com/flex/2/langref/package.html#Array()

These sorts of things are either (a) because ECMA Script defines these
functions or (b) because legacy versions of ActionScript have always done
this (I apologize for not researching this for you right now).

The as operator returns null if the cast fails, where as Type(uncastVar)
will throw a coercion exception if it fails to cast or "coerce" the
uncastVar to Type. Besides the aforementioned restriction due to intrinsic
type global functions, it's a matter of style as to whether you need to know
about a failed cast or not.





 ------------------------------
*From:* [email protected] [mailto:[EMAIL PROTECTED] *On
Behalf Of *dougmccune
*Sent:* Thursday, January 11, 2007 6:11 PM
*To:* [email protected]
*Subject:* [flexcoders] Casting a variable - Best Practice?

 Quick question (I know both work, just wondering what people do in
practice):

Option A: var castVar:Type = uncastVar as Type;

OR

Option B: var castVar:Type = Type(uncastVar);

I've been going with using option A (with "as") mainly because calling
Array(uncastVar) or ArrayCollection(uncastVar) does not cast to Array
or ArrayCollection, but instead instantiates new Arrays, which is
confusing. So instead of trying to remember to do most of my casting
using Type(variable) unless I'm trying to cast to Array, I figured it
was easier to just always use "as".

Also, is there a specific reason for the choice to not allow
Array(var) to simply cast to an array? It seems a little odd that
casting that works for every other datatype doesn't for one or two.




--
Teoti Graphix
http://www.teotigraphix.com

Blog - Flex2Components
http://www.flex2components.com

You can find more by solving the problem then by 'asking the question'.

Reply via email to