我正在尝试将对象放入将被屏蔽的影片剪辑中 允许用户滚动浏览它们
我当前的解决方案是为每个添加事件监听器 内部影片剪辑...
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");
}
由于可以有一个内部影片剪辑的可变列表,因此可以获取 不规则(而且丑陋:)所以我试图为父对象添加一个监听器 这是目前的尝试...
outer_mc.addEventListener(MouseEvent.MOUSE_DOWN, swapMovie);
function swapMovie(e:MouseEvent) {
trace(e.currentTarget.name + " selected");
}
但是这只是返回“outer_mc”并使用 target 而不是 currentTarget 返回Flash分配的随机实例编号instance128、instance 23等。
有没有人有一个解决方案可以获取子对象的实例名称 这适用于 ActionScript 3 吗?我看过了,最接近的是使用 不返回实际实例名称的目标解决方案。
最佳答案
尝试:
for (var i:int = 0; i < outer_mc.numChildren; i++) {
var child:* = outer_mc.getChildAt(i);
child.addEventListener(MouseEvent.MOUSE_DOWN, swapMovie);
}
在这种情况下,它将循环遍历outer_mc的所有子级,并向每个子级添加鼠标按下事件监听器。
关于actionscript-3 - Actionscript 3,获取内部影片剪辑的实例名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13089147/