AS3通过引用Nullify对象

时间:2014-03-15 00:07:33

标签: actionscript-3

我似乎有人问这个问题,并得到答案说这在AS3中是不可能的。

所以我有一个名为destroymc的函数:

function destroymc(mcname:MovieClip):void{
    mcname = null
}

这不会破坏我想破坏的动画片段。因为它是通过引用传递的。

真的没办法让这个工作吗?

感谢。

1 个答案:

答案 0 :(得分:0)

据我所知,嗯,摧毁'在AS3.0中的MovieClip,您需要删除对它的所有引用,并且您需要将其从父项中删除。然后GC可以收集它。

如果你有一个MovieClip数组,那么这样的东西可以工作。

var mcs:Array;
// populate array

// to destroy the first one
mcs[0].parent.removeChild(mcs[0]); // remove the first element from its parent
mcs.shift(); // remove the first element in the array

所以如果你想要一个函数,你可以将数组传递给它

function destroymc(mcs:Array){
    mcs[0].parent.removeChild(mcs[0]);
    mcs.shift();
}

我在这里使用数组,因为你需要使用动态生成的MovieClip和实体管理器和东西这样的函数。我希望这会有所帮助。

相关问题