Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 监视从显示列表中添加/删除MovieClips的事件?_Actionscript 3 - Fatal编程技术网

Actionscript 3 监视从显示列表中添加/删除MovieClips的事件?

Actionscript 3 监视从显示列表中添加/删除MovieClips的事件?,actionscript-3,Actionscript 3,我有一个movieclip,我们称之为“myMC”,它非常长(5000帧),在这个过程中,许多嵌套的movieclip作为孩子添加/从“myMC”中删除 在不参考嵌套剪辑的情况下,是否有一种方法可以将侦听器添加到myMC中,并在对象被添加/删除时进行侦听(与Event.added类似)?可以。只需为事件添加一个事件侦听器。已将添加到父级MovieClip。添加子项时,添加的事件将弹出并调用您的处理程序。您可以从处理程序中读取event.target属性来检索特定的子实例。event.ADDED和

我有一个movieclip,我们称之为“myMC”,它非常长(5000帧),在这个过程中,许多嵌套的movieclip作为孩子添加/从“myMC”中删除


在不参考嵌套剪辑的情况下,是否有一种方法可以将侦听器添加到myMC中,并在对象被添加/删除时进行侦听(与Event.added类似)?

可以。只需为
事件添加一个事件侦听器。已将
添加到父级
MovieClip
。添加子项时,添加的
事件将弹出并调用您的处理程序。您可以从处理程序中读取
event.target
属性来检索特定的子实例。

event.ADDED
event.REMOVED
将对您有所帮助

这些事件都是真实的,所以没有必要听直系家长的话。您可以在任何显示祖先中捕获这些事件,如下面的示例所示

import flash.events.Event;
import flash.display.Sprite;

var onAdded:Function = function (event:Event) : void
{
    // event.target references the display object being added
    trace(event.type +": '" + event.target.name+"'");
}

var onRemoved:Function = function (event:Event) : void
{
    // event.target references the display object being removed
    trace(event.type+": '" + event.target.name+"'");
}

addEventListener(Event.ADDED, onAdded);
addEventListener(Event.REMOVED, onRemoved);

var container:Sprite = new Sprite();
container.name = 'Container here'
addChild(container);

var test:Sprite = new Sprite();
test.name = "I am the one!";
container.addChild(test);
container.removeChild(test);

/*
added: 'Container here'
added: 'I am the one!'
removed: 'I am the one!'
*/

错误,event.target将不包含您最近添加的movieclip。@Artemix,您确定吗?官方文件指出,情况应如此: