我正在尝试将对象放在将要屏蔽的影片剪辑中 允许用户滚动浏览
我目前的解决方案是为每个人添加事件列表器 内部电影剪辑......
outer_mc.myObject1.addEventListener(MouseEvent.MOUSE_DOWN, swapMovie);
outer_mc.myObject2.addEventListener(MouseEvent.MOUSE_DOWN, swapMovie);
outer_mc.myObject3.addEventListener(MouseEvent.MOUSE_DOWN, swapMovie);
outer_mc.myObject4.addEventListener(MouseEvent.MOUSE_DOWN, swapMovie);
outer_mc.myObject5.addEventListener(MouseEvent.MOUSE_DOWN, swapMovie);
outer_mc.myObject6.addEventListener(MouseEvent.MOUSE_DOWN, swapMovie);
outer_mc.myObject7.addEventListener(MouseEvent.MOUSE_DOWN, swapMovie);
outer_mc.myObject8.addEventListener(MouseEvent.MOUSE_DOWN, swapMovie);
outer_mc.myObject9.addEventListener(MouseEvent.MOUSE_DOWN, swapMovie);
outer_mc.myObject10.addEventListener(MouseEvent.MOUSE_DOWN, swapMovie);
outer_mc.myObject11.addEventListener(MouseEvent.MOUSE_DOWN, swapMovie);
outer_mc.myObject12.addEventListener(MouseEvent.MOUSE_DOWN, swapMovie);
function swapMovie(e:MouseEvent) {
trace(e.currentTarget.name + " selected");
}
由于可以获得内部影片剪辑的变量列表 unruley(和丑陋:)所以我正在尝试为父对象添加一个监听器 这是目前的尝试......
outer_mc.addEventListener(MouseEvent.MOUSE_DOWN, swapMovie);
function swapMovie(e:MouseEvent) {
trace(e.currentTarget.name + " selected");
}
然而,这只返回“outer_mc”并使用target而不是currentTarget 返回随机实例编号Flash分配instance128,实例23等
有没有人有一个解决方案来获取子对象的实例名称 那将在动作3中起作用?我看了,最接近的是使用了 目标解决方案,它不返回实际的实例名称。
答案 0 :(得分:2)
尝试:
for (var i:int = 0; i < outer_mc.numChildren; i++) {
var child:* = outer_mc.getChildAt(i);
child.addEventListener(MouseEvent.MOUSE_DOWN, swapMovie);
}
在这种情况下,它将循环遍历outer_mc的所有子节点,并将鼠标按下事件侦听器添加到每个子节点。
答案 1 :(得分:1)
您可以尝试做类似的事情:
function swapMovie(e:MouseEvent) {
var current = e.target;
parent = current.parent;
while (parent != e.currentTarget)
{
current = current.parent;
parent = current.parent;
}
//Current should be your object, now
}
基本上它的作用是上升一级,直到它找到outer_mc,然后停止,并返回其被点击的子项。