Posted By

konrad_ha on 05/18/11


Tagged

as3 Parent displaylist displayobjectcontainer


Versions (?)

switch parent while remaining position


 / Published in: ActionScript 3
 

  1. function switchDisplayObjectContainer(obj:DisplayObject, oldContainer:DisplayObjectContainer, newContainer:DisplayObjectContainer):void {
  2. var startLocalPos:Point = new Point(obj.x, obj.y);
  3. var globalPos:Point = oldContainer.localToGlobal(startLocalPos);
  4.  
  5. newContainer.addChild(obj);
  6.  
  7. var newLocalPos:Point = newContainer.globalToLocal(globalPos);
  8. obj.x = newLocalPos.x;
  9. obj.y = newLocalPos.y;
  10. }

Report this snippet  

You need to login to post a comment.