Hello :)
Use an argument in the constructor of you class to passed-in the parent
reference of your display

public function MyDisplay( target:DisplayObjectContainer = null )
{
    if ( target != null )
    {
         target.addChild( this ) ;
    }
}

PS : your code isn't valid in the constructor of a DisplayObject the "stage"
and "parent" properties are "null" ! Only in the main class of your
application this two attributes are not null.

EKA+ :)

2009/8/17 ACE Flash <acefl...@gmail.com>

> Hi guys,
>
> I am curious about if am able to add the DisplayObject into a container
> without using addChild() method, this class is very simple...
>
>
>
>   1. package
>   2. {
>   3. import flash.display.Sprite;
>   4. import flash.events.Event;
>   5.
>   6. public class MyClass extends Sprite
>   7. {
>   8.
>   9. public function MyClass ()
>   10. {
>   11. //addEventListener( Event.ADDED_TO_STAGE , addedHandler );
>   12. parent.addChild(this);
>   13. }
>   14. /*
>   15. private function addedHandler( e:Event ):void
>   16. {
>   17. removeEventListener( Event.ADDED_TO_STAGE , addedHandler );
>   18.
>   19. parent.addChild(this); // how could I retrieve the instance name of
>   this"?
>   20. }
>   21. */
>   22. }
>   23. }
>
>
>
> I'd like to do something like....
>
>
> var do:MyClass = new MyClass();
> //addChild(do) // added it into displayobject without using this method
> here
>
>
> Is that possible? any suggestions are welcome  :)
>
> Thank you
> _______________________________________________
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to