Since you're looping through the parent's children, not all children might be 
LiquidObject instances.
Which is why it works when you check if it "is" a LiquidObject

if (parent.getChildAt(i) is LiquidObject)

The following will indeed work, because casting like that is allowed:

 if (parent.getChildAt(i) is LiquidObject) {
     trace(LiquidObject(parent.getChildAt(i)));
 }

However using the "as" operator is better practice, because you can't always 
cast usting "Class()" as Darren explains in his 
article. For instance Array(myArray) will actually try to create a new Array 
instead of casting it..

So in this case it is just a "better practice approach":

 if (parent.getChildAt(i) is LiquidObject) {
     trace((parent.getChildAt(i) as LiquidObject));
 }

note: you don't really need to cast it to just "trace()" the object, but I 
guess you're actually trying to do something with the 
retrieved instance, in which case you have to:

(parent.getChildAt(i) as LiquidObject).doSomethingLiquidObjectSpecific();

regards,
Muzak

----- Original Message ----- 
From: "Paul Chang" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Thursday, June 21, 2007 7:42 PM
Subject: Re: [Flashcoders] Type Coercion Failed: Odd behavior.


> 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


_______________________________________________
[email protected]
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

Reply via email to