I don't understand why you would not want to write a single line of code in the class where it would provide the most clarity, and instead write MORE code in another class obscuring the behavior that is going on. In other words, you're writing more code to write the same code. You're going to write addChild either way, why make it more complicated than it needs to be?

Always follow the KISS principle.


BTW, Ekameleon, you should use

if (target)

Instead of

if (target != null)



ACE Flash wrote:
ekameleon, you are the man! so sweet.

Thanks

On Mon, Aug 17, 2009 at 1:54 PM, ekameleon <ekamel...@gmail.com> wrote:

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

_______________________________________________
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