闪光AS3的理解localToGlobal [英] Flash as3 understanding localToGlobal

查看:126
本文介绍了闪光AS3的理解localToGlobal的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是有麻烦了解Flash的localToGlobal一点点功能。我有一个影片剪辑,这是嵌套一大堆其他影片剪辑的内部。当该嵌套剪辑被点击,我想找到自己的位置,并通过一个量,使得嵌套剪辑在阶段(基本上是我拥有的是一个树形图,和我想要的效果的中心移到最上面的含夹是,treeContainer平移,点击的分支为舞台的中心)

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. When that nested clip is clicked, I want to find its position, and moved the topmost containing clip by an amount such that the nested clip is in the center of the stage (basically what I have is a tree diagram, and the effect I want is that the treeContainer pans to the clicked "branch" as the center of the stage)

所以我有这样的:

var treePoint = new Point (treeContainer.x,treeContainer.y); //since treePoint's parent is the stage, don't need global here.

var groupPoint = new Point (groupClip.x,groupClip.y);
var groupPointGlobal = groupClip.localToGlobal(groupPoint);
var stageCenter = new Point (int(stage.stageWidth/2),int(stage.stageHeight)/2);

var shiftAmount = ???

感谢您的帮助,您可以提供。

Thanks for any help you can provide.

推荐答案

一个剪辑的x,y位置始终是相对于它的父。所以,除非它是舞台上的孩子,或者父母是在0,0 - 您可以使用localToGlobal给你这是在舞台上的位置

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.

但是从它的声音,你想要去的其他方式,做globalToLocal吧?

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

globalToLocal将返回一个局部位置的基础上,全局位置。

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

所以,如果你想设置一个剪辑的本地位置,这样它会被放置在屏幕中心 - 让我们假设它是320240

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.

有意义吗?

这篇关于闪光AS3的理解localToGlobal的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆