27 posts
  • Has been part of the Envato Community for over 3 years
pctechtv says

I am learning AS3 and was wondering can a Class file contain a method to call it self? Kind of like:

function someMethod():void { addChild(this); }

Of course the method is in a package and class. My quick answer to my self is no, but I know I have a lot to learn.

3769 posts Community Moderator
  • Helps us moderate the forums
  • Contributed a tutorial on Tuts+
  • Located in Netherlands
  • Made it to the Authors' Hall of Fame
+9 more
Joost Moderator says

Basically what you’re implicitly saying is this.addChild(this);. That’s quite a paradoxial situation and would lead to an endless recursion ;) So somebody correct me if I’m wrong, but it seems to me that this is not something you might want to do.

You could always just try it out and see what happens, though :delicious:

1662 posts
  • Has referred 50+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Won a Most Wanted contest
+9 more
flashedge says

That would cause an infinite loop and probably your computer would crash, get fire and everybody dies.

1234 posts
  • Has been part of the Envato Community for over 6 years
  • Has referred 50+ members
  • Has sold $75,000+ on Envato Market and is now an Elite Author
  • Has collected 50+ items on Envato Market
+5 more
MBMedia says

In the scene graph each object has a property of a parent and list of children (or just parent if it’s not an object that can contain children). For an object to be it’s own parent would mean that it’s own concatenated transform data (such as it’s concatenatedMatrix) would be used as it’s parent concatenated transform data to combine with it’s local transform data, which would result in it infinitely applying any transform information, such as if you set the x to 10 it’s concatentated x value would be 10 * infinity. Basically, it would go against the idea of what forward kinematics (objects containing each other) is for, and I’d assume that if you attempted it it would throw either a runtime or compiler error saying not to do that.

Edit: looked it up, it’s error #2024, “An object cannot be added as a child of itself.”

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by