_myParent.addChild(this);
Let's break this down...
_myParent
This is a reference to another object, which happens to be the object's parent on the display list. There are many reasons for an object to have a reference to its parent. They are closely related in structure, so likely have reasons to communicate with each other. So, having a reference to the display list parent isn't an issue.
addChild()
Calling one of the parent's public methods isn't an issue. That's what methods are for. If this were a property of the parent, it would be invasive. Calling this method won't directly alter the parent's state. The parent will carry out this function at its own discretion.
this
The fact that the argument in this case happens to be self-referential is a coincidence. If the argument were something trivial such as new Shape()
, it would seem less awkward. But, since an object is essentially "adding itself", it seems something like a person lifting himself up by his/her bootstraps. But, this isn't real life; it's computer programming, and it makes sense when read by its syntax.
Actionscript needed to name the function something. The other alternative for getting a child onto the display list could have been addToParent()
, which would still have the same awkward effect when trying to add a child from the parent -- _myChild.addToParent(this)
.
So, while there are no objects being violated in this awkward predicament, there is a more natural way of writing addChild()
statements, and that's to add children from parents, instead of the other way around because that's the order laid down by the syntax. So, try to use the natural way, and when that fails, the other way is still okay, just a little awkward.