@raven-worx setting it to undefined doesn't help. I have the undefined set already in the code. it doesn't seem to work at all.
Seems like the anchors i am trying to set and unset do not take affect on myqmlitem ?

were not getting unset by doing setting it undefined. That means that myqmlcomponent remained anchored to top and horizontalCenter. if they were really getting unset then I would be able to drag myqmlcomponent to different X and Y coordinates.

But the good news is that I figured this out. I needed to refer to myqmlcomponent when setting it anchors to undefined. Like below: