具有 localToGlobal 问题的动态 MC 路径
我将 MC (bread_mc) 的多个实例添加到容器 MC (wall_mc) 中。 wall_mc 已添加到商店类中,这就是我调用其余函数的地方。 wall_mc 也用 mouseX & 左右滚动。鼠标 Y 值。我已经设置了一个函数来将 bread_mc 添加到墙上不同的 x/y 位置。
函数调用:
fillShelves(bread_mc,Bread,600,200);
函数:
function fillShelves(productMc:MovieClip,className:Class,productX:Number, productY:Number) {
newProduct = new className();
newProduct.x=productX;
newProduct.y=productY;
shelf_mc.addChildAt(newProduct,1);
newProduct.addEventListener(MouseEvent.MOUSE_DOWN, dragProduct, false, 0, true);
}
我添加了一个拖/放操作,其中 bread_mc 将弹回其架子 x/y 位置。不过,我希望当用户在 bread_mc 上按下 MOUSE_DOWN 时,它会被添加到最高深度,因此在拖动时,它会保持在其他 mc 的前面(例如,一个有购物车的人)。
我的问题是,每当我调用函数 DragProduct(); 时
function dragProduct(e:MouseEvent):void {
currMC = (e.target as MovieClip);
this.addChild(currMC);
stage.addEventListener(MouseEvent.MOUSE_UP, dropProduct);
}
我点击的该死的 bread_mc 向右移动的距离与我滚动 wall_mc 的距离相同。我尝试强制 currMC 坚持使用 mouseX/Y,但这需要 ENTER_FRAME 函数,这看起来很复杂。
我研究并发现了 localToGlobal。与此类似的方法:
point = new Point(currMC.x, currMC.y);
currMC.localToGlobal(point);
trace(point.x);
我真的不知道我是否使用正确,但我认为我的问题在于我需要 currMC 路径来向上移动显示列表树并获取全局舞台 X/Y位置。我不太确定如何使用 localToGlobal 方法实现动态路径。
任何帮助将不胜感激。即使它在这里>阅读此内容。谢谢
I'm adding several instances of an MC (bread_mc) into a container MC (wall_mc). wall_mc has been added to a shop class and that is where i'm called the rest of my functions from. Also the wall_mc is scrolled left and right with mouseX & mouseY values. I've set up a function to add the bread_mc to the wall at different x/y positions.
Function call:
fillShelves(bread_mc,Bread,600,200);
Function:
function fillShelves(productMc:MovieClip,className:Class,productX:Number, productY:Number) {
newProduct = new className();
newProduct.x=productX;
newProduct.y=productY;
shelf_mc.addChildAt(newProduct,1);
newProduct.addEventListener(MouseEvent.MOUSE_DOWN, dragProduct, false, 0, true);
}
I've added a drag/drop where the bread_mc will snap back to it's shelf x/y position. However i'd like that when user MOUSE_DOWN on bread_mc it is added to the highest depth so, while dragged, it stays infront of other mc's (a person with a shopping cart for example).
My problem is, whenever I call the function dragProduct();
function dragProduct(e:MouseEvent):void {
currMC = (e.target as MovieClip);
this.addChild(currMC);
stage.addEventListener(MouseEvent.MOUSE_UP, dropProduct);
}
The damn bread_mc I click on moves to the right by the same amount that I've scrolled the wall_mc. I have tried forcing the currMC to stick with the mouseX/Y but that would need an ENTER_FRAME function and that seems so convoluted.
I researched and found localToGlobal. Methods simliar to this:
point = new Point(currMC.x, currMC.y);
currMC.localToGlobal(point);
trace(point.x);
I really don't even know if i'm using it right, But I think my problem lies in the fact that I need the currMC path to travel up the display list tree and get the global stage X/Y position. I'm not too sure how to implement a dynamic path with the localToGlobal method.
Any help would be appreciated. Even if it's go here>read this. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您拖动的
bread_mc
moveclip 会移动,因为它正在移动到具有不同原点的不同容器。在您的fillShelves
函数中,您将bread_mc
添加为shelf_mc
的子项。但在dragProduct
函数中,您将其添加到this
中。只需尝试将bread_mc
添加到shelf_mc
而不是this
即可。忘记所有 localToGlobal 的东西。当您调用
addChild
时,它会将目标带到其所有同级目标的前面。Your dragged
bread_mc
moveclip moves because it is being move to a different container that has a different origin. In yourfillShelves
function you are addingbread_mc
as a child ofshelf_mc
. But in thedragProduct
function you are adding it tothis
. Just try addingbread_mc
toshelf_mc
rather thanthis
. And forget about all the localToGlobal stuff.When you call
addChild
, it will bring the target to the front of all its siblings.