Hmmmmm... A typing puzzle. :)
At runtime dg.selectedItem is indeed a ResourceVO instance, otherwise this
would be false yet it is always true:
flash.util.trace( dg.selectedItem is ResourceVO ); // true
I am not sure what the AS3 compiler does when it encounters a cast like Class(
obj )?
I expect that bytecode is added to process the instance through the class
constructor at runtime, which if typed correctly is a waste of bytecode and
player energy.
After looking in more detail, the error is definitely at compile time and seems
to be when the value of objTemp is set.
The error as follows:
"Implicit coercion of a value with static type 'Object' to a possibly unrelated
type 'com.crap.vo:ResourceVO'"
I just pinged someone on the player team and they returned this bit of strange
new AS3 goodness:
objTemp = dg.selectedItem as ResourceVO;
This compiles without error. This uses the "as" operator to return the
dg.selectedItem as a ResourceVO assuming it is one, otherwise it would return
one of the default null types, detail here:
http://livedocs.macromedia.com/labs/1/flex/langref/operators.html#as
Regardless, right or wrong, it would be nice to know how this actually works in
AS3.
I do know that AS3 is very performance sensitive to strong typing but supports
loose typing and dynamic access as well. Given AS3 is still in part an
interpreted language, the behavior may fall in either direction. Method and
Property access at runtime is dramatically improved with strong typing as the
player can JIT the bytecode into native machine code. When an untyped variable
is encountered, the player must shift into a slower interpreted mode, hence all
the compile-time warnings denoting untyped vars. And that is what gets me about
this error, the compiler will allow an untyped variable by with a warning, but
when we have typing spot on correct, it will throw a compile time error. It
sure seems like a bug to me.
It will be very interesting to see where this falls.
Cheers,
Cynergy Systems, Inc.
Theodore Patrick
Sr. Consultant
[EMAIL PROTECTED]
tel: 1.866.CYNERGY
http://www.cynergysystems.com
________________________________________
From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Jens
Halm
Sent: Wednesday, April 12, 2006 5:49 PM
To: Ted Patrick
Subject: Re: [flexcoders] programatically assigning an ArrayCollection as the
DataProvider bug...
> Geoffrey,
> This is a common misconception about return types. In the Flex
> docs, the type specified is the lowest subclass supported for the
> returned data. If the return type is Object, this can include Array,
> Boolean, String, Number, components, and most custom classes.
> But alas that is not the issue here, Houston we have a bug!
Hm, I think the misconception is on your side. Of course the return
type Object allows almost anything at *runtime*, but the *compile*
time type is just Object and you have to cast to any other concrete
type. This is the case in ActionScript 2/3 and any other strongly
typed language I know (e.g. Java). In fact this is the reason why
Java 5 introduced Generics: You do not have to cast any more if you
take something out of a collection. But in AS we don't have Generics
(yet) so we have to cast. Without the need to cast in such a case the
whole type system would not make much sense.
Of course you have to differentiate between upcasting and downcasting!
Upcasting does not need an explicit cast:
var vo:ValueObject = new ValueObject();
var o:Object = vo; // upcast, casting is implicit!
But when downcasting you have to do an explicit cast:
var o:Object = dg.selectedItem;
var vo:ValueObject = ValueObject(o); // downcast, need to cast!
Don't know the issues related to the valueOf method. But... its return
type is Object too, so I think it's the other way around: The bug is
that the compiler does not complain when you use valueOf..
Jens
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
________________________________________
YAHOO! GROUPS LINKS
* Visit your group "flexcoders" on the web.
* To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
* Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
________________________________________
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.385 / Virus Database: 268.4.1/309 - Release Date: 4/11/2006
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/