Flash as3 understanding localToGlobal

前端 未结 1 1466
余生分开走
余生分开走 2020-12-10 05:49

I\'m just having a little bit of trouble understanding Flash\'s localToGlobal functionality. I have a movieClip, which is nested inside a whole bunch of other movieclips. Wh

相关标签:
1条回答
  • 2020-12-10 06:36

    A clip's x,y location is always relative to it's parent. So unless it's a child of the stage, or the parent is at 0,0 - you can use localToGlobal to give you it's location on the stage.

    var globalPoint:Point = myClip.localToGlobal(new Point(0,0));
    

    That would give you the global position of that clip.

    But from the sounds of it, you want to go the other way and do globalToLocal right ?

    globalToLocal will return a local position , based on a global location.

    So if you wanted to set a clip's local position so that it will be positioned at center of the screen -- lets assume it's 320,240.

    var localPoint:Point = myClip.parent.globalToLocal(new Point(320,240));
    myClip.x = localPoint.x;
    myClip.y = localPoint.y;
    

    We use the parent, because thats what the clip will be be relative to.

    make sense?

    0 讨论(0)
提交回复
热议问题