Sander,
   .parent is of type DisplayObjectContainer, not DisplayObject. Only
DisplayObjectContainers have the .addChild() method.

   If you use DisplayObjectContainer as r's type, it should all work fine.

HTH,
   Ian

On Wed, Dec 3, 2008 at 12:06 PM, Sander Schuurman
<[EMAIL PROTECTED]> wrote:
> Hi cool list.
>
> In the following piece of code, I cannot make the type of the parent 
> reference to DisplayObject. If I set the reference-type to *, all works fine. 
> But there must be a more sophisticated way that produces cleaner code.
>
> Anyone?
>
> Code:
> public class Test extends Sprite
> {
>            public var o:DisplayObject;
>            public var r:DisplayObject; // produces error see below
>            // public var r:*; // works like a charm
>
>            public function Test( obj :DisplayObject )
>            {
>                        r = obj.parent;
>                        o = obj;
>                        r.addChild(this); // this line produces the error
>            }
> }
>
> Error:
> 1061: Call to a possibly undefined method addChild through a reference with 
> static type flash.display:DisplayObject.
> _______________________________________________
> Flashcoders mailing list
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to