Thanks for this reference. I performed a simple test and it works.
However, for my particular example, I receive an error.
var liquidObject:LiquidObject = parent.getChildAt(i) as LiquidObject;
assigns null to liquidObject.
The only thing that has worked for me so far is:
if (parent.getChildAt(i) is LiquidObject) {
trace(LiquidObject(parent.getChildAt(i)));
}
My only explanation is that I'm attempting to perform this cast
WITHIN the LiquidObject class itself.
I currently have the stated workaround, but any further insights
would be of interest to me.
Best,
Paul
On Jun 21, 2007, at 6:19 AM, Muzak wrote:
You should always use the new "as" operator.
This article might help:
http://www.darronschall.com/weblog/archives/000211.cfm
regards,
Muzak
----- Original Message -----
From: "Amir T Rocker" <[EMAIL PROTECTED]>
To: <flashcoders@chattyfig.figleaf.com>
Sent: Thursday, June 21, 2007 11:39 AM
Subject: Re: [Flashcoders] Type Coercion Failed: Odd behavior.
Hi,
i experienced the same behaviour using this type of cast
var somVar = Caster( Castee );
sometimes it works and sometimes it doesnt ...
I tried to use the 'as' operator and that suddenly works where
above coed failed.
var someVar = list.getItemAt( i ) as TypeToCast;
I hope maybe that works for you too. I havent figured the casting
rules quite yet. So if anybody can explain it
its really appreciated :)
Best of luck
Amir
Am 04:07 AM 6/21/2007 schrieben Sie:
Hello,
I've created a custom class:
LiquidObject extends Sprite
I then create several instances of LiquidObject and add them as
children to a parent Sprite.
If I cycle through and trace the children as such:
for (var i:int=0;i<parent.numChildren;i++) {
trace(parent.getChildAt(i));
}
Each trace shows the correct type of object:
[object LiquidObject]
When I tried to access a property specific to LiquidObject
(LiquidObject.selected) it does not recognize this to be a property
because it thinks it's dealing with a general Sprite. So, I attempt
to coerce to type LiquidObject as such:
for (var i:int=0;i<parent.numChildren;i++) {
trace(LiquidObject(parent.getChildAt(i)).selected);
}
Unfortunately, I receive an error stating that I can't coerce type
Sprite to LiquidObject. I would think that this would be allowed
since (a) LiquidObject extends Sprite and (b) parent.getChildAt
(i) is
already presenting a type LiquidObject in the trace.
Any suggestions would be appreciated.
Thanks in advance.
Paul
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com